Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does C++ need operator synonyms? [duplicate]

Tags:

c++

operators

While looking for the operator list of C++ on Wikipedia, I found an article about operator synonyms:

C++ defines[6] keywords to act as aliases for a number of operators: and (&&), bitand (&), and_eq (&=), or (||), bitor (|), or_eq (|=), xor (^), xor_eq (^=), not (!), not_eq (!=), and compl (~). These can be used exactly the same way as the punctuation symbols they replace, as they are not the same operator under a different name, but rather simple token replacements for the name (character string) of the respective operator. This means that the expressions (a > 0 and flag) and (a > 0 && flag) have identical meanings. It also mean that, for example, the bitand keyword may be used to replace not only the bitwise-and operator but also the address-of operator, and it can even be used to specify reference types (e.g., int bitand ref = n). The ISO C specification makes allowance for these keywords as preprocessor macros in the header file iso646.h. For compatibility with C, C++ provides the header ciso646, inclusion of which has no effect.

Then I am wondering: Why do we need these operator synonyms? It would be nice if someone provide some use case.

like image 566
ashiquzzaman33 Avatar asked Oct 09 '15 14:10

ashiquzzaman33


1 Answers

All answers are here: http://en.cppreference.com/w/cpp/language/operator_alternative

Basically, those are symbols which can not be represented in ISO 646 character codeset.

like image 151
SergeyA Avatar answered Nov 17 '22 03:11

SergeyA