NUMA++ 0.12.0
Loading...
Searching...
No Matches
flags.hpp File Reference

Contains definitions for bitwise operators for enums. More...

#include <type_traits>

Go to the source code of this file.

Macros

#define NUMAPP_ENABLE_BITFLAG(enum)
 Enables numapp bitwise operators in overload set for the specified enumeration enum.
 

Functions

Bitwise operators for enabled enums

Convenience function to compose bit flags using bitwise OR and AND operators.

Example:

using numapp::operator|; // Bring in numapp::operator| in this scope
MyEnum f = MyEnum::A | MyEnum::B;
f &= MyEnum::A;
MyFunc(f);
MyFunc(MyEnum::A | MyEnum::B);
template<class Enum, typename = typename std::enable_if<IsFlagEnum<Enum>::value>::type>
constexpr Enum numapp::operator| (Enum lhs, Enum rhs) noexcept
 
template<class Enum, typename = typename std::enable_if<IsFlagEnum<Enum>::value>::type>
constexpr Enum & numapp::operator|= (Enum &lhs, Enum rhs) noexcept
 Sets lhs with logical OR between lhs and rhs.
 
template<class Enum, typename = typename std::enable_if<IsFlagEnum<Enum>::value>::type>
constexpr Enum numapp::operator& (Enum lhs, Enum rhs) noexcept
 
template<class Enum, typename = typename std::enable_if<IsFlagEnum<Enum>::value>::type>
constexpr Enum & numapp::operator&= (Enum &lhs, Enum rhs) noexcept
 Sets lhs with logical AND between lhs and rhs.
 

Detailed Description

Contains definitions for bitwise operators for enums.

SPDX-License-Identifier: LGPL-3.0-only

Definition in file flags.hpp.

Macro Definition Documentation

◆ NUMAPP_ENABLE_BITFLAG

#define NUMAPP_ENABLE_BITFLAG ( enum)
Value:
template <>\
struct IsFlagEnum<enum> : std::true_type { \
static_assert(std::is_enum_v<enum>); \
};

Enables numapp bitwise operators in overload set for the specified enumeration enum.

Note
This macro must be used inside the namespace numapp.

Definition at line 19 of file flags.hpp.

Function Documentation

◆ operator&()

template<class Enum, typename = typename std::enable_if<IsFlagEnum<Enum>::value>::type>
Enum numapp::operator& ( Enum lhs,
Enum rhs )
nodiscardconstexprnoexcept
Returns
logical AND between lhs and rhs

Definition at line 93 of file flags.hpp.

◆ operator|()

template<class Enum, typename = typename std::enable_if<IsFlagEnum<Enum>::value>::type>
Enum numapp::operator| ( Enum lhs,
Enum rhs )
nodiscardconstexprnoexcept
Returns
logical OR between lhs and rhs

Definition at line 76 of file flags.hpp.