CKTIS / C++
bitor — alternative spelling of bitwise OR
`bitor` is an alternative spelling of the C++ operator `|`. The built-in operator performs bitwise inclusive OR: a result bit is set when the corresponding bit of at least one operand is set. Do not confuse it with logical `or` (`||`).
Version: C++23; repository compiler flag, production runtime not attested
Syntax
lhs bitor rhsbitor denotes the same operator as |; only the spelling changes, not its behavior or precedence. It is a reserved language token, so it cannot be used as a variable name. No header or macro definition is required.
For the built-in operator, operands must have integral or unscoped enumeration types. The usual arithmetic conversions apply. Each result bit is 1 when at least one corresponding operand bit is 1. The operator groups left-to-right; this does not specify the order in which its operands are evaluated.
Do not confuse bitor with or: or is an alternative spelling of ||. Built-in || produces a bool and skips evaluating its right operand when its left operand is true. Built-in bitor does not provide this short-circuit behavior. Meanwhile, or_eq means |=, not |.
In the example, read bitor write combines the masks 0b0100u and 0b0010u, producing 0b0110u, or decimal 6. The static_assert declarations check the expected value and equivalence to read | write at compile time.
Examples
#include <iostream>
int main() {
constexpr unsigned read = 0b0100u;
constexpr unsigned write = 0b0010u;
constexpr unsigned permissions = read bitor write;
static_assert(permissions == 0b0110u);
static_assert(permissions == (read | write));
std::cout << permissions << '\n';
}
Result
6
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.