CKTIS / C++
Left-shift assignment operator (<<=)
The <<= operator shifts the left operand's bits to the left and stores the result in the same object. The left operand is evaluated only once, and the valid shift-count range depends on its type after integral promotion.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
lhs <<= countThe built-in operator lhs <<= count combines left shift and assignment: it behaves like lhs = lhs << count, but evaluates lhs only once. The left operand must be a modifiable lvalue of integral type; the right operand may have integral or unscoped enumeration type. This is not stream output.
The shift operands undergo integral promotions. For width N of the promoted left type, the result corresponds to multiplication by 2^count modulo 2^N; vacated positions are zero-filled. The result is then converted to the type of lhs. A negative count or count >= N causes undefined behavior—even when lhs is zero.
The right operand is evaluated before the left operand. The assignment expression yields an lvalue referring to the modified object; assignment operators associate right-to-left. These rules describe the built-in operator, not an arbitrary class overload of operator<<=.
In the example, shifting 3u by two positions produces 12. This entry targets C++23; the supplied source is an evolving working draft, not a frozen C++23 text.
Examples
#include <iostream>
int main() {
unsigned int value = 3u;
value <<= 2;
std::cout << value << '\n';
}
Result
12
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.