cppreference gives the following code for a possible for_each_n implementation:
template<class InputIt, class Size, class UnaryFunction>
InputIt for_each_n(InputIt first, Size n, UnaryFunction f)
{
for (Size i = 0; i < n; ++first, (void) ++i) {
f(*first);
}
return first;
}
Why is the result of ++i cast to void? Is it because we discard the result of ++i to suppress the possible compiler warning? If so, why is the ++first not cast to void as well? Because operator , implicitly discards it?