I am trying to find the rationale behind having the re- and post- versions of the increment and decrement operators overloadable separately.
In my mind, and in every implementation I have ever seen of these operators for any type of class, these are the same operator (=do the same thing) and just differ in when it is called.
It would seem much more logical to me that the designers of C++ would have had one ++
operator, and the compiler would call it as needed, either before or after reading the value (or, more likely, at the previous or next sequence point, which I think is equivalent)
So, the question is: Does anyone have an example of a case/class where these might not be implemented the same? Or does anyone know/guess the rationale behind this design choice?
For those that prefer to look at code than read text in a question, here is the summary:
For what type T
(a user defined class representing anything you want) would it make sense for the following 2 lines to not have the same side effects:
T v;
v++;
++v;
EDIT
To quote @Simple's comment below, which I hope clarifys the question:
Why post-increment (overloading) is in the language if the compiler can just do a copy itself and do the pre-increment
EDIT 2
Since the question is apparently unclear to many, here is another explanation:
Consider the following two lines:
b = a++;
b = ++a;
If it was one operator (for the sake of argument, I will call the operator +a+), the first line would be translated by the compiler into
b = a;
+a+;
and the second into
+a+;
b = a;