Recommend replacing postincrement with preincrement in any_of(), all_of(), non_of()
Closed this issue · 3 comments
spillner commented
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
The problem with this code is that it does the wrong thing on empty collections; i.e, when last == first
mclow commented
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
Changed in commit #4d598e84100b535fbb47bab16db313f4b1107287