mclow / Boost.Algorithm

Proposed Boost.Algorithm Library
7 stars 2 forks source link

Recommend replacing postincrement with preincrement in any_of(), all_of(), non_of() #4

Closed spillner closed 13 years ago

spillner commented 13 years ago

do { if (!p(*first) return false; } while (++first != last);

would be more readable and sometimes more efficient (and perhaps even better-supported for some nonstandard iterator types.)

mclow commented 13 years ago

The problem with this code is that it does the wrong thing on empty collections; i.e, when last == first

mclow commented 13 years ago

To avoid postincrement, it might be better to use a degenerate for loop:

for ( ; first != last; ++first ) if ( !p (*first)) return false; return true;

mclow commented 13 years ago

Changed in commit #4d598e84100b535fbb47bab16db313f4b1107287