From ec0dba97f2490cf1e7bca835b808fea93ace2fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Fri, 3 Nov 2017 11:33:48 +0100 Subject: [PATCH] Arrays - Fixed bad asserts in iterators --- include/ebcl/inline/Arrays.hh | 48 ++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/include/ebcl/inline/Arrays.hh b/include/ebcl/inline/Arrays.hh index 29576d1..f8a9401 100644 --- a/include/ebcl/inline/Arrays.hh +++ b/include/ebcl/inline/Arrays.hh @@ -709,31 +709,35 @@ M_HDR_ inline T& M_CNAME_::operator[]( M_HDR_ inline M_CNAME_T_& M_CNAME_::operator++ () noexcept { - assert( valid( ) ); - pos_ += D; + assert( array_ ); + pos_ = std::min( ptrdiff_t( array_->size( ) ) , + std::max( ptrdiff_t( -1 ) , pos_ + D ) ); return *this; } M_HDR_ inline M_CNAME_T_ M_CNAME_::operator++ (int) noexcept { - assert( valid( ) ); + assert( array_ ); auto copy( *this ); - pos_ += D; + pos_ = std::min( ptrdiff_t( array_->size( ) ) , + std::max( ptrdiff_t( -1 ) , pos_ + D ) ); return copy; } M_HDR_ inline M_CNAME_T_& M_CNAME_::operator-- () noexcept { - assert( valid( ) ); - pos_ -= D; + assert( array_ ); + pos_ = std::min( ptrdiff_t( array_->size( ) ) , + std::max( ptrdiff_t( -1 ) , pos_ - D ) ); return *this; } M_HDR_ inline M_CNAME_T_ M_CNAME_::operator-- (int) noexcept { - assert( valid( ) ); + assert( array_ ); auto copy( *this ); - pos_ -= D; + pos_ = std::min( ptrdiff_t( array_->size( ) ) , + std::max( ptrdiff_t( -1 ) , pos_ - D ) ); return copy; } @@ -765,7 +769,7 @@ M_HDR_ inline ptrdiff_t M_CNAME_::operator -( M_HDR_ inline M_CNAME_T_& M_CNAME_::operator +=( const ptrdiff_t value ) noexcept { - assert( valid( ) ); + assert( array_ ); pos_ = std::min( ptrdiff_t( array_->size( ) ) , std::max( ptrdiff_t( -1 ) , pos_ + value * D ) ); return *this; @@ -774,7 +778,7 @@ M_HDR_ inline M_CNAME_T_& M_CNAME_::operator +=( M_HDR_ inline M_CNAME_T_& M_CNAME_::operator -=( const ptrdiff_t value ) noexcept { - assert( valid( ) ); + assert( array_ ); pos_ = std::min( ptrdiff_t( array_->size( ) ) , std::max( ptrdiff_t( -1 ) , pos_ - value * D ) ); return *this; @@ -912,31 +916,35 @@ M_HDR_ inline T const& M_CNAME_::operator[]( M_HDR_ inline M_CNAME_T_& M_CNAME_::operator++ () noexcept { - assert( valid( ) ); - pos_ += D; + assert( array_ ); + pos_ = std::min( ptrdiff_t( array_->size( ) ) , + std::max( ptrdiff_t( -1 ) , pos_ + D ) ); return *this; } M_HDR_ inline M_CNAME_T_ M_CNAME_::operator++ (int) noexcept { - assert( valid( ) ); + assert( array_ ); auto copy( *this ); - pos_ += D; + pos_ = std::min( ptrdiff_t( array_->size( ) ) , + std::max( ptrdiff_t( -1 ) , pos_ + D ) ); return copy; } M_HDR_ inline M_CNAME_T_& M_CNAME_::operator-- () noexcept { - assert( valid( ) ); - pos_ -= D; + assert( array_ ); + pos_ = std::min( ptrdiff_t( array_->size( ) ) , + std::max( ptrdiff_t( -1 ) , pos_ - D ) ); return *this; } M_HDR_ inline M_CNAME_T_ M_CNAME_::operator-- (int) noexcept { - assert( valid( ) ); + assert( array_ ); auto copy( *this ); - pos_ -= D; + pos_ = std::min( ptrdiff_t( array_->size( ) ) , + std::max( ptrdiff_t( -1 ) , pos_ - D ) ); return copy; } @@ -968,7 +976,7 @@ M_HDR_ inline ptrdiff_t M_CNAME_::operator -( M_HDR_ inline M_CNAME_T_& M_CNAME_::operator +=( const ptrdiff_t value ) noexcept { - assert( valid( ) ); + assert( array_ ); pos_ = std::min( ptrdiff_t( array_->size( ) ) , std::max( ptrdiff_t( -1 ) , pos_ + value * D ) ); return *this; @@ -977,7 +985,7 @@ M_HDR_ inline M_CNAME_T_& M_CNAME_::operator +=( M_HDR_ inline M_CNAME_T_& M_CNAME_::operator -=( const ptrdiff_t value ) noexcept { - assert( valid( ) ); + assert( array_ ); pos_ = std::min( ptrdiff_t( array_->size( ) ) , std::max( ptrdiff_t( -1 ) , pos_ - value * D ) ); return *this;