Whether what I want is bad-practice or not, I wonder if one can make a distinction between the following cases:
MyType A, B, C;
Case1:
B << A;
Case2:
C << (B << A);
What i want in Case1 is that B is MODIFIED such that it is concatenated with A. In Case2 on the other hand, I want that B is NOT modified but instead a temporary object equivalent to 'B concatenated with A' be returned (and C is modified and concatenated with that temp object).
Is this possible? If so what should be the operator overloading syntax and variants in C++? I tried r-value versions of operators RHS params; and const/non-const overloads; and also & / && post-fixing the method to discriminate LHS of overload operator.
Any ideas? (I really tried a lot to avoid duplicate questions)
operator <<=and avoid the ambiguity altogether?B << Ais another way of writingoperator<<(B, A)orB.operator<<(A). The operator has no knowledge about the rest of the expression, like if there are any()'s present.B<<Aandoperator<<(B,A). The standard states: "If an operator function is invoked using operator notation, argument evaluation is sequenced as specified for the built-in operator" (It is not really relevant to the question.)