I would love to bitshift an integral value by an enum value.
Example usage:
Creating a flag enum based on an existing enum:
enum class A {
X = 0,
Y = 1,
Z = 2
};
enum class AFlags {
XF = 1 << A::X,
YF = 1 << A::Y,
ZF = 1 << A::Z
};
General Bitshifting by an enum value:
A a = A::Y;
auto flag = 1 << a;
Currently i have that implemented by the C++23 code:
template<typename E>
requires std::is_enum_v<E>
constexpr auto operator<<(const std::integral auto& a, const E& b) {
return a << std::to_underlying(b);
}
I suggest implementing a bitshift in both directions by an enum. Maybe you want to add bitshifting an enum by an integral as well, and maybe even an enum by an enum.
I would love to bitshift an integral value by an enum value.
Example usage:
Creating a flag enum based on an existing enum:
General Bitshifting by an enum value:
Currently i have that implemented by the C++23 code:
I suggest implementing a bitshift in both directions by an enum. Maybe you want to add bitshifting an enum by an integral as well, and maybe even an enum by an enum.