Search code examples
c++operatorsassignment-operator

Why is ~= the only non-logical assignment operator missing in C++?


Out of curiosity, why the bitwise operator ~ is the only non-logical operator that does not have an assignment version in C++, i.e. ~=? All relational and bitwise operators have an assignment version, but ~= is missing. Is there a particular reason for that?

For all the operators in C++, see for instance: http://www.tutorialspoint.com/cplusplus/cpp_operators.htm


Solution

  • All operators from which compound assignments are made are binary. Tilde, on the other hand, is unary, so there is no easy way to make a compound assignment from it, because there is nothing to put on the right-hand side.

    Other unary operands, such as unary minus and logical NOT ! operator, also do not have compound assignments.