Under 24.2.3 Input iterators
, the C++ standard specifies one of the requirements of input iterator as the expression (void)r++
being equivalent to (void)++r
.
You can also see this at cppreference.
What is that expression? What is the significance of this requirement? Why is it needed?
It looks like a C style cast to void of the result of r++
or ++r
but I don't think that's what it really is. That said, to digress a bit, it looks like I can define a void
conversion operator inside a class. Both gcc and clang compile it but clang gives the warning:
warning: conversion function converting 'C' to 'void' will never be used
It is a C-style cast to void
. What the standard means to say is that r++
and ++r
must be equivalent if their return value is not used, i.e., that they have the same side effect.
It basically means that the pre- or post-incrementation of an iterator shall produce the same effect, though returned values might (and will in the general case) differ.
That's just the way of C++ specs to state the obvious in the most obfuscated possible way :).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With