Arrays - Fixed bad asserts in iterators

This commit is contained in:
Emmanuel BENOîT 2017-11-03 11:33:48 +01:00
parent 1c0527caab
commit ec0dba97f2

View file

@ -709,31 +709,35 @@ M_HDR_ inline T& M_CNAME_::operator[](
M_HDR_ inline M_CNAME_T_& M_CNAME_::operator++ () noexcept M_HDR_ inline M_CNAME_T_& M_CNAME_::operator++ () noexcept
{ {
assert( valid( ) ); assert( array_ );
pos_ += D; pos_ = std::min( ptrdiff_t( array_->size( ) ) ,
std::max( ptrdiff_t( -1 ) , pos_ + D ) );
return *this; return *this;
} }
M_HDR_ inline M_CNAME_T_ M_CNAME_::operator++ (int) noexcept M_HDR_ inline M_CNAME_T_ M_CNAME_::operator++ (int) noexcept
{ {
assert( valid( ) ); assert( array_ );
auto copy( *this ); auto copy( *this );
pos_ += D; pos_ = std::min( ptrdiff_t( array_->size( ) ) ,
std::max( ptrdiff_t( -1 ) , pos_ + D ) );
return copy; return copy;
} }
M_HDR_ inline M_CNAME_T_& M_CNAME_::operator-- () noexcept M_HDR_ inline M_CNAME_T_& M_CNAME_::operator-- () noexcept
{ {
assert( valid( ) ); assert( array_ );
pos_ -= D; pos_ = std::min( ptrdiff_t( array_->size( ) ) ,
std::max( ptrdiff_t( -1 ) , pos_ - D ) );
return *this; return *this;
} }
M_HDR_ inline M_CNAME_T_ M_CNAME_::operator-- (int) noexcept M_HDR_ inline M_CNAME_T_ M_CNAME_::operator-- (int) noexcept
{ {
assert( valid( ) ); assert( array_ );
auto copy( *this ); auto copy( *this );
pos_ -= D; pos_ = std::min( ptrdiff_t( array_->size( ) ) ,
std::max( ptrdiff_t( -1 ) , pos_ - D ) );
return copy; return copy;
} }
@ -765,7 +769,7 @@ M_HDR_ inline ptrdiff_t M_CNAME_::operator -(
M_HDR_ inline M_CNAME_T_& M_CNAME_::operator +=( M_HDR_ inline M_CNAME_T_& M_CNAME_::operator +=(
const ptrdiff_t value ) noexcept const ptrdiff_t value ) noexcept
{ {
assert( valid( ) ); assert( array_ );
pos_ = std::min( ptrdiff_t( array_->size( ) ) , pos_ = std::min( ptrdiff_t( array_->size( ) ) ,
std::max( ptrdiff_t( -1 ) , pos_ + value * D ) ); std::max( ptrdiff_t( -1 ) , pos_ + value * D ) );
return *this; return *this;
@ -774,7 +778,7 @@ M_HDR_ inline M_CNAME_T_& M_CNAME_::operator +=(
M_HDR_ inline M_CNAME_T_& M_CNAME_::operator -=( M_HDR_ inline M_CNAME_T_& M_CNAME_::operator -=(
const ptrdiff_t value ) noexcept const ptrdiff_t value ) noexcept
{ {
assert( valid( ) ); assert( array_ );
pos_ = std::min( ptrdiff_t( array_->size( ) ) , pos_ = std::min( ptrdiff_t( array_->size( ) ) ,
std::max( ptrdiff_t( -1 ) , pos_ - value * D ) ); std::max( ptrdiff_t( -1 ) , pos_ - value * D ) );
return *this; return *this;
@ -912,31 +916,35 @@ M_HDR_ inline T const& M_CNAME_::operator[](
M_HDR_ inline M_CNAME_T_& M_CNAME_::operator++ () noexcept M_HDR_ inline M_CNAME_T_& M_CNAME_::operator++ () noexcept
{ {
assert( valid( ) ); assert( array_ );
pos_ += D; pos_ = std::min( ptrdiff_t( array_->size( ) ) ,
std::max( ptrdiff_t( -1 ) , pos_ + D ) );
return *this; return *this;
} }
M_HDR_ inline M_CNAME_T_ M_CNAME_::operator++ (int) noexcept M_HDR_ inline M_CNAME_T_ M_CNAME_::operator++ (int) noexcept
{ {
assert( valid( ) ); assert( array_ );
auto copy( *this ); auto copy( *this );
pos_ += D; pos_ = std::min( ptrdiff_t( array_->size( ) ) ,
std::max( ptrdiff_t( -1 ) , pos_ + D ) );
return copy; return copy;
} }
M_HDR_ inline M_CNAME_T_& M_CNAME_::operator-- () noexcept M_HDR_ inline M_CNAME_T_& M_CNAME_::operator-- () noexcept
{ {
assert( valid( ) ); assert( array_ );
pos_ -= D; pos_ = std::min( ptrdiff_t( array_->size( ) ) ,
std::max( ptrdiff_t( -1 ) , pos_ - D ) );
return *this; return *this;
} }
M_HDR_ inline M_CNAME_T_ M_CNAME_::operator-- (int) noexcept M_HDR_ inline M_CNAME_T_ M_CNAME_::operator-- (int) noexcept
{ {
assert( valid( ) ); assert( array_ );
auto copy( *this ); auto copy( *this );
pos_ -= D; pos_ = std::min( ptrdiff_t( array_->size( ) ) ,
std::max( ptrdiff_t( -1 ) , pos_ - D ) );
return copy; return copy;
} }
@ -968,7 +976,7 @@ M_HDR_ inline ptrdiff_t M_CNAME_::operator -(
M_HDR_ inline M_CNAME_T_& M_CNAME_::operator +=( M_HDR_ inline M_CNAME_T_& M_CNAME_::operator +=(
const ptrdiff_t value ) noexcept const ptrdiff_t value ) noexcept
{ {
assert( valid( ) ); assert( array_ );
pos_ = std::min( ptrdiff_t( array_->size( ) ) , pos_ = std::min( ptrdiff_t( array_->size( ) ) ,
std::max( ptrdiff_t( -1 ) , pos_ + value * D ) ); std::max( ptrdiff_t( -1 ) , pos_ + value * D ) );
return *this; return *this;
@ -977,7 +985,7 @@ M_HDR_ inline M_CNAME_T_& M_CNAME_::operator +=(
M_HDR_ inline M_CNAME_T_& M_CNAME_::operator -=( M_HDR_ inline M_CNAME_T_& M_CNAME_::operator -=(
const ptrdiff_t value ) noexcept const ptrdiff_t value ) noexcept
{ {
assert( valid( ) ); assert( array_ );
pos_ = std::min( ptrdiff_t( array_->size( ) ) , pos_ = std::min( ptrdiff_t( array_->size( ) ) ,
std::max( ptrdiff_t( -1 ) , pos_ - value * D ) ); std::max( ptrdiff_t( -1 ) , pos_ - value * D ) );
return *this; return *this;