MeshLib
 
Loading...
Searching...
No Matches
MRFlagOperators.h
Go to the documentation of this file.
1#pragma once
2
3#include <type_traits>
4
5// Generates operators for a enum (at namespace scope).
6#define MR_MAKE_FLAG_OPERATORS( T ) MR_MAKE_FLAG_OPERATORS_CUSTOM( static, T )
7
8// Generates operators for a enum (at class scope).
9#define MR_MAKE_FLAG_OPERATORS_IN_CLASS( T ) MR_MAKE_FLAG_OPERATORS_CUSTOM( friend, T )
10
11// Generates operators for a enum (with a custom prefix before each function).
12#define MR_MAKE_FLAG_OPERATORS_CUSTOM( prefix, T ) \
13 [[nodiscard, maybe_unused]] prefix constexpr T operator&( T a, T b ) { return T( ::std::underlying_type_t<T>( a ) & ::std::underlying_type_t<T>( b ) ); } \
14 [[nodiscard, maybe_unused]] prefix constexpr T operator|( T a, T b ) { return T( ::std::underlying_type_t<T>( a ) | ::std::underlying_type_t<T>( b ) ); } \
15 [[nodiscard, maybe_unused]] prefix constexpr T operator~( T a ) { return T( ~::std::underlying_type_t<T>( a ) ); } \
16 [[maybe_unused]] prefix constexpr T &operator&=( T &a, T b ) { return a = a & b; } \
17 [[maybe_unused]] prefix constexpr T &operator|=( T &a, T b ) { return a = a | b; } \
18 [[nodiscard, maybe_unused]] prefix constexpr T operator*( T a, bool b ) { return b ? a : T{}; } \
19 [[nodiscard, maybe_unused]] prefix constexpr T operator*( bool a, T b ) { return a ? b : T{}; } \
20 [[maybe_unused]] prefix constexpr T &operator*=( T &a, bool b ) { return a = a * b; }