14template <
typename T,
typename E>
15 requires(std::is_enum_v<E> && std::is_integral_v<T>)
38 [[nodiscard]]
constexpr operator T()
const {
55 template <
typename... Es>
56 requires(std::is_same_v<Es, E> && ...)
66 template <
typename... Es>
67 requires(std::is_same_v<Es, E> && ...)
78 template <
typename... Es>
79 requires(std::is_same_v<Es, E> && ...)
80 constexpr
TBitFlag<T, E> &changeBit(
bool on, Es... es) {
81 (changeBit_(on, es), ...);
89 template <
typename... Es>
90 requires(std::is_same_v<Es, E> && ...)
92 (toggleBit_(es), ...);
101 template <
typename... Es>
102 requires(std::is_same_v<Es, E> && ...)
103 [[nodiscard]]
constexpr bool onBit(Es... es)
const {
104 return (onAnyBit(es...));
112 template <
typename... Es>
113 requires(std::is_same_v<Es, E> && ...)
114 [[nodiscard]]
constexpr bool onAnyBit(Es... es)
const {
115 return (onBit_(es) || ...);
123 template <
typename... Es>
124 requires(std::is_same_v<Es, E> && ...)
125 [[nodiscard]]
constexpr bool onAllBit(Es... es)
const {
126 return (onBit_(es) && ...);
134 template <
typename... Es>
135 requires(std::is_same_v<Es, E> && ...)
136 [[nodiscard]]
constexpr bool offBit(Es... es)
const {
137 return offAllBit(es...);
145 template <
typename... Es>
146 requires(std::is_same_v<Es, E> && ...)
147 [[nodiscard]]
constexpr bool offAllBit(Es... es)
const {
148 return (offBit_(es) && ...);
156 template <
typename... Es>
157 requires(std::is_same_v<Es, E> && ...)
158 [[nodiscard]]
constexpr bool offAnyBit(Es... es)
const {
159 return (offBit_(es) || ...);
167 template <
typename... Es>
168 requires(std::is_same_v<Es, E> && ...)
169 [[nodiscard]]
constexpr T
maskBit(Es... es)
const {
170 return bits & makeMask(es...);
177 template <
typename... Es>
178 requires(std::is_same_v<Es, E> && ...)
179 [[nodiscard]]
constexpr T
makeMask(Es... es)
const {
180 return (makeMask_(es) | ...);
204 return on ? set(mask) : reset(mask);
210 [[nodiscard]]
constexpr bool on(T mask)
const {
211 return (bits & mask) != 0;
217 [[nodiscard]]
constexpr bool onAll(T mask)
const {
218 return (bits | mask) == bits;
224 [[nodiscard]]
constexpr bool off(T mask)
const {
225 return (bits & mask) == 0;
246 typedef std::underlying_type_t<E> EI;
247 static constexpr size_t MAX_CAPACITY = std::numeric_limits<T>::digits;
253 ASSERT(
static_cast<EI
>(e) < MAX_CAPACITY);
261 ASSERT(
static_cast<EI
>(e) < MAX_CAPACITY);
270 ASSERT(
static_cast<EI
>(e) < MAX_CAPACITY);
271 change(on, makeMask_(e));
278 ASSERT(
static_cast<EI
>(e) < MAX_CAPACITY);
279 changeBit_(offBit_(e), e);
286 [[nodiscard]]
constexpr bool onBit_(E e)
const {
287 ASSERT(
static_cast<EI
>(e) < MAX_CAPACITY);
288 return on(makeMask_(e));
295 [[nodiscard]]
constexpr bool offBit_(E e)
const {
296 ASSERT(
static_cast<EI
>(e) < MAX_CAPACITY);
297 return off(makeMask_(e));
305 ASSERT(
static_cast<EI
>(e) < MAX_CAPACITY);
306 return static_cast<T
>(1) <<
static_cast<T
>(e);
Wrapper around an integral type with an enum corresponding to its bits.
constexpr bool offBit_(E e) const
Checks if a specific bit is off.
constexpr bool on(T mask) const
Checks if any bits are on in the specified mask.
constexpr TBitFlag< T, E > & resetBit(Es... es)
Resets the corresponding bits for the provided enum values.
constexpr TBitFlag(T mask)
Constructor that initializes the bit flags with a given mask.
constexpr bool onBit(Es... es) const
Checks if any of the corresponding bits for the provided enum values are on.
constexpr T maskBit(Es... es) const
Creates an applied mask of the corresponding bits for the provided enum values.
constexpr bool onAllBit(Es... es) const
Checks if all of the corresponding bits for the provided enum values are on.
constexpr T makeMask(Es... es) const
Creates a mask of the corresponding bits for the provided enum values.
constexpr bool onAnyBit(Es... es) const
Checks if any of the corresponding bits for the provided enum values are on.
constexpr void resetBit_(E e)
Internal. Resets a specific bit.
constexpr T getDirect() const
Gets the current bit mask.
T bits
The bit mask representing the flags.
constexpr void toggleBit_(E e)
Internal. Toggles a specific bit.
constexpr void setBit_(E e)
Internal. Sets a specific bit.
constexpr bool offBit(Es... es) const
Checks if all of the corresponding bits for the provided enum values are off.
constexpr void setDirect(T mask)
Sets the bits using a direct mask.
constexpr void makeAllZero()
Resets all the bits to zero.
constexpr TBitFlag< T, E > & set(T mask)
Sets the bits using a direct mask.
constexpr bool offAllBit(Es... es) const
Checks if all of the corresponding bits for the provided enum values are off.
constexpr bool offAnyBit(Es... es) const
Checks if any of the corresponding bits for the provided enum values are off.
constexpr TBitFlag< T, E > & reset(T mask)
Resets the bits using a direct mask.
constexpr bool onAll(T mask) const
Checks if all bits are on in the specified mask.
constexpr TBitFlag(E e)
Constructor that initializes the bit flags with a given enum.
constexpr void changeBit_(bool on, E e)
Internal. Changes a specific bit.
constexpr TBitFlag< T, E > & operator=(const TBitFlag< T, E > &rhs)
Assignment operator.
constexpr bool onBit_(E e) const
Checks if a specific bit is on.
constexpr TBitFlag< T, E > & change(bool on, T mask)
Changes the bits using a direct mask.
constexpr bool off(T mask) const
Checks if all bits are off in the specified mask.
constexpr TBitFlag()
Default constructor, initializes all flags to off.
constexpr T makeMask_(E e) const
Creates a mask for a specific bit.
constexpr TBitFlag< T, E > & toggleBit(Es... es)
Toggles the corresponding bits for the provided enum values.