diff --git a/alib2std/src/extensions/vector.hpp b/alib2std/src/extensions/vector.hpp index 7566ca0631129ad5408c7f839c231026fcd64cd5..b9e0c8695ffd7ceb9da46683a0fcb0035e3bac08 100644 --- a/alib2std/src/extensions/vector.hpp +++ b/alib2std/src/extensions/vector.hpp @@ -192,20 +192,18 @@ ext::vector < bool, Ts ... > & operator <<= ( ext::vector < bool, Ts ... > & A, return A; // shift by the rest dist - { - vectorBoolInternalType bits1 { }; - vectorBoolInternalType bits2 { }; + vectorBoolInternalType bits1 { }; + vectorBoolInternalType bits2 { }; - // it might be more clear to iterate from the begining. However this is working nicely - auto itA = A.begin ( ); + // it might be more clear to iterate from the begining. However this is working nicely + auto itA = A.begin ( ); - while ( itA < A.end ( ) ) { - bits2 = * ( itA._M_p ); - * ( itA._M_p ) = * ( itA._M_p ) << distWithin | bits1 >> backDist; - bits1 = bits2; + while ( itA < A.end ( ) ) { + bits2 = * ( itA._M_p ); + * ( itA._M_p ) = * ( itA._M_p ) << distWithin | bits1 >> backDist; + bits1 = bits2; - itA._M_p ++; - } + itA._M_p ++; } return A; @@ -227,6 +225,10 @@ ext::vector < bool, Ts ... > & operator >>= ( ext::vector < bool, Ts ... > & A, size_t sizeWithin = A.size ( ) % vectorBoolInternalTypeInBits; size_t backDist = vectorBoolInternalTypeInBits - distWithin; + // upper part of the last word in the ext::vector can contain some garbage so it needs to be cleared + if ( sizeWithin != 0 ) + * ( ( A.end ( ) - 1 )._M_p ) &= getMask ( sizeWithin ); + // shift blocks if needed if ( distBlocks ) { auto itA = A.begin ( ); @@ -244,25 +246,19 @@ ext::vector < bool, Ts ... > & operator >>= ( ext::vector < bool, Ts ... > & A, return A; // shift by the rest dist - { - vectorBoolInternalType bits1 { }; - vectorBoolInternalType bits2 { }; + vectorBoolInternalType bits1 { }; + vectorBoolInternalType bits2 { }; - // it might be more clear to iterate from the begining. However this is working nicely - auto itAReverse = A.end ( ) - 1; - - // upper part of the last word in the ext::vector can contain some garbage so it needs to be cleared - if ( sizeWithin != 0 ) - * ( itAReverse._M_p ) &= getMask ( sizeWithin ); + // it might be more clear to iterate from the begining. However this is working nicely + auto itAReverse = A.end ( ) - 1; - // simulate behavior of reverse iterator - while ( itAReverse >= A.begin ( ) ) { - bits2 = * ( itAReverse._M_p ); - * ( itAReverse._M_p ) = * ( itAReverse._M_p ) >> distWithin | bits1 << backDist; - bits1 = bits2; + // simulate behavior of reverse iterator + while ( itAReverse >= A.begin ( ) ) { + bits2 = * ( itAReverse._M_p ); + * ( itAReverse._M_p ) = * ( itAReverse._M_p ) >> distWithin | bits1 << backDist; + bits1 = bits2; - itAReverse._M_p --; - } + itAReverse._M_p --; } return A;