ToyGine2 26.2.0
Game Engine for retro consoles
Loading...
Searching...
No Matches
toy::EnableBitwiseOperators< T > Class Template Reference

Primary template: disables generic bitwise operators for T unless specialized. More...

Static Public Attributes

static constexpr bool enable = false
 When true, the bitwise operator overloads in this header apply to T. The primary template sets false.

Detailed Description

template<typename T>
class toy::EnableBitwiseOperators< T >

Primary template: disables generic bitwise operators for T unless specialized.

Specialize (manually or with ENABLE_BITWISE_OPERATORS(T)) so that enable is true for a given scoped enum. The generic operator overloads in this header are only instantiated when EnableBitwiseOperators<T>::enable is true.

Template Parameters
TScoped enumeration type (enum class).

Usage Example

#include "core.hpp"
namespace toy {
enum class MyFlags : unsigned { a = 1u, b = 2u, c = 4u };
} // namespace toy
namespace toy {
constexpr MyFlags combined = MyFlags::a | MyFlags::b;
constexpr MyFlags masked = combined & MyFlags::a;
constexpr MyFlags inverted = ~MyFlags::a;
} // namespace toy
#define ENABLE_BITWISE_OPERATORS(T)
Specializes toy::EnableBitwiseOperators so that enable is true for the scoped enum T.
Definition bitwise_enum.hpp:208
Umbrella header for the engine core module.
Root namespace containing all engine modules.
Definition version.inl:30

Key Features

  • ⚙️ Opt-in: No operators are added until you specialize the trait (typically via ENABLE_BITWISE_OPERATORS).
  • Constrained overloads: Participation is explicit (requires EnableBitwiseOperators<T>::enable).
  • constexpr / noexcept: Usable in constant evaluation when operands and the underlying type allow it.
  • No allocation: Pure forwarding to integral bitwise operations on the underlying type.

Performance Characteristics

Each operation is a short inline forwarding to one or two integer operations; complexity is O(1) per call with no heap use.

Safety Guarantees

  • The trait does not check that enumerators are disjoint bits; mixing overlapping values is a logic error.
  • All declared operations are noexcept.
  • For signed underlying types, unary ~ follows the usual two's-complement bit pattern for the underlying width.
Note
Prefer an unsigned underlying type for flag enums to reduce surprises with ~ and with mixing signed literals.
See also
ENABLE_BITWISE_OPERATORS

Member Data Documentation

◆ enable

template<typename T>
bool toy::EnableBitwiseOperators< T >::enable = false
staticconstexpr

When true, the bitwise operator overloads in this header apply to T. The primary template sets false.


The documentation for this class was generated from the following file: