CKTIS / C++
Bitwise left-shift operator <<
The built-in << operator shifts an integer value's bits left, filling vacated positions with zeros. The shift count must be within the width of the promoted left operand. Do not confuse it with stream insertion.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
lhs << countBuilt-in lhs << count accepts integral or unscoped enumeration types and performs integral promotions. The result has the promoted left operand's type; the right operand does not widen it. The operation does not modify lhs.
For C++23, the result corresponds to lhs × 2^count modulo 2^N, where N is the result type's width, including for signed types. Vacated bits become zero, and bits shifted beyond the width are discarded. Prefer unsigned types for bit masks.
A negative count or count >= N causes undefined behavior. Account for promotions: a small type may be promoted to int. Shift operators associate left-to-right; addition has higher precedence, so value << 1 + 1 means value << (1 + 1).
In the example, 3u << 2 produces 12u. By contrast, std::cout << shifted uses an overloaded stream-insertion operator, not a bit shift. The supplied document is an evolving draft, not a frozen C++23 publication.
Examples
#include <iostream>
int main() {
constexpr unsigned int value = 3u;
constexpr unsigned int shifted = value << 2;
static_assert(shifted == 12u);
std::cout << shifted << '\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.