mclow/Boost.Algorithm

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

Closed this issue · 3 comments

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.)

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

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

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

Changed in commit #4d598e84100b535fbb47bab16db313f4b1107287