CKTIS / C++
and_eq — alternative spelling of bitwise AND assignment
and_eq is a reserved C++ keyword and an alternative spelling of &=. For built-in integral types, it performs bitwise AND and stores the result in the left operand. It is not the logical operator and.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
lhs and_eq rhs; // equivalent spelling: lhs &= rhs;and_eq is an alternative spelling of the token &=: lhs and_eq rhs has the same meaning as lhs &= rhs. It requires no header or macro definition. It is a reserved keyword, so it cannot be used as a variable or function name.
For built-in integral types, the operator computes bitwise AND and stores the result in the left operand. A result bit is 1 only when both corresponding operand bits are 1. The usual arithmetic conversions apply, and the result is converted to the left operand's type when stored. The left operand must be a modifiable lvalue, such as a non-const integer variable.
Built-in lhs and_eq rhs corresponds to lhs = lhs & rhs, except that lhs is evaluated only once. Do not confuse it with and, which means &&: and_eq does not perform logical short-circuit evaluation. For class types, it can invoke an overloaded operator&=; the alternative spelling does not change operator selection.
In the example, flags is 0b1101u and mask is 0b1010u. After flags and_eq mask, the remaining value is 0b1000u, so the program prints 8. The displayed code was run unchanged in an isolated environment, and its standard output matched the expected output exactly. The supplied source is an evolving working draft, not a frozen C++23 edition.
Examples
#include <iostream>
int main() {
unsigned int flags = 0b1101u;
const unsigned int mask = 0b1010u;
flags and_eq mask;
std::cout << flags << '\n';
}
Result
8
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.