What's the difference between "and_eq" and "&="?

551 views c++

I've been looking at the c++ reference site, and I came across this article about the and_eq keyword. This article said:

alternative operators: as an alternative for &=

about the and_eq operator. I could not find anything online about the difference between and_eq and &=. Is it exactly the same as the &= operator, or is there a difference? If there is a difference, when should I use each?

answered question

Have you read another article about alternative operator representation?

2 Answers


If you click through the "alternative operators" link on the very page you've linked, you'll see this text:

There are alternative spellings for several operators and other tokens that use non-ISO646 characters. In all respects of the language, each alternative token behaves exactly the same as its primary token, except for its spelling (the stringification operator can make the spelling visible). The two-letter alternative tokens are sometimes called "digraphs"

Note that certain compilers are non-standard by default and don't allow for alternative spellings, so you'll either enforce the standard compliance mode to make it possible to use the alternative spellings, or just use the primary ones.

posted this

It is literally the same thing if you #include <iso646.h> where the alternate operators are defined (on my Visual Studio 2017 machine at least):

  #define and_eq    &=
  #define bitand    &
  #define bitor |
  #define compl ~
  #define not   !
  #define not_eq    !=
  #define or        ||
  #define or_eq |=
  #define xor   ^
  #define xor_eq    ^=

posted this

Have an answer?


Please login first before posting an answer.