If my C++ class has overloaded the bitwise-OR operator (|
), does the C++ language spec guarantee that the arguments passed to a series of calls to that operator will be evaluated left-to-right? Or is the order-of-evaluation implementation-defined (or undefined)?
(IIRC C++'s built-in |
operator has implementation-defined order-of-evaluation; but perhaps it is different when the operator has been overloaded for a class?)
Below is a program that exemplifies what I'm asking: Is this program guaranteed to print out 0 1 2 3 4
(as it does on the Mac I'm currently sitting at), or might it legally print out 4 3 2 1 0
(or some other ordering) in certain environments?
#include <iostream>
class mytype_t
{
public:
mytype_t(int v) : _val(v) {/* empty */}
mytype_t operator | (const mytype_t & rhs) const {return (_val | rhs._val);}
private:
int _val;
};
mytype_t func(int v)
{
std::cout << v << std::endl;
return mytype_t(v);
}
int main(int, char **)
{
mytype_t x = func(0) | func(1) | func(2) | func(3) | func(4);
return 0;
}