Praxeolitic
Praxeolitic

Reputation: 24099

(void)r++ requirement of input iterator

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

Upvotes: 5

Views: 287

Answers (2)

kuroi neko
kuroi neko

Reputation: 8661

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

Upvotes: 3

Wintermute
Wintermute

Reputation: 44063

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.

Upvotes: 7

Related Questions