-3

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?

Pika Supports Ukraine
  • 3,612
  • 10
  • 26
  • 42
  • 1
    Have you read [another article](https://en.cppreference.com/w/cpp/language/operator_alternative) about alternative operator representation? –  Nov 09 '18 at 01:47
  • Also see [“&&” and “and” operator in C](https://stackoverflow.com/q/17365271/1708801) – Shafik Yaghmour Nov 09 '18 at 01:59
  • 1
    For the question of when to use each, it is when the system you are using does not have characters like `&`, `=`, `^` etc. Yes, such computers exist, they don't use ASCII, and they run C++ too. –  Nov 09 '18 at 02:09

2 Answers2

3

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.

milleniumbug
  • 15,379
  • 3
  • 47
  • 71
0

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    ^=
  • 1
    Not exactly. The `` header is deprecated and has no effect. This is C++, not C. –  Nov 09 '18 at 01:55
  • Ah yes, I was just noticing that and coming back to edit my answer but you are correct, the include is not necessary in C++ but the effect is the same, they are identical. To answer the original question, "when" you should use them, that is a matter of personal style but I haven't seen them used in much if any code; the only time I've used them is when I wrote a "script"-like function and wanted it to read as close to English as possible: `wait_until(current_game_state_is() or elapsed(10));` – James Thrush Nov 09 '18 at 02:00