what does the "void" mean here in a for-statement?

Hi, I get confused when I read the code from this page:
http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare

1
2
3
4
5
6
7
8
9
10
template<class InputIt1, class InputIt2>
bool lexicographical_compare(InputIt1 first1, InputIt1 last1,
                             InputIt2 first2, InputIt2 last2)
{
    for ( ; (first1 != last1) && (first2 != last2); ++first1, (void) ++first2 ) {
        if (*first1 < *first2) return true;
        if (*first2 < *first1) return false;
    }
    return (first1 == last1) && (first2 != last2);
}


What does the '(void) ++first2' mean here?
> What does the '(void) ++first2' mean here?

Nothing much, really.

It just ensures that the sequencing operator (aka comma operator) that is used is the built-in sequencing operator.
It takes care of the edge-case that some user defined type which has overloaded operator, might be involved.
Is that a special syntax, or is it just the result of ++first2 being cast to void? I didn't know it was possible to force the compiler to not use an overloaded operator.
> Is that a special syntax, or is it just the result of ++first2 being cast to void?

Just the result of ++first2 being cast to void.
(We just can't define a user-defined overloaded binary operator where one of the operands is of type void)
Topic archived. No new replies allowed.