2#include <UnCompute/Base/Base.h>
7#define UN_BIT(n) (1 << (n))
11 inline constexpr std::enable_if_t<std::is_enum_v<TEnum>, std::underlying_type_t<TEnum>> un_enum_cast(TEnum value)
13 return static_cast<std::underlying_type_t<TEnum>
>(value);
19#define UN_ENUM_OPERATORS(Name) \
20 inline constexpr Name operator|(Name a, Name b) \
22 return static_cast<Name>(un_enum_cast(a) | un_enum_cast(b)); \
24 inline constexpr Name& operator|=(Name& a, Name b) \
28 inline constexpr Name operator&(Name a, Name b) \
30 return static_cast<Name>(un_enum_cast(a) & un_enum_cast(b)); \
32 inline constexpr Name& operator&=(Name& a, Name b) \
36 inline constexpr Name operator^(Name a, Name b) \
38 return static_cast<Name>(un_enum_cast(a) ^ un_enum_cast(b)); \
40 inline constexpr Name& operator^=(Name& a, Name b) \
44 inline constexpr Name operator~(Name a) \
46 return static_cast<Name>(~un_enum_cast(a)); \
53 inline constexpr bool IsAllowedAsFlags = std::is_enum_v<T> | std::is_integral_v<T>;
57 template<
class TFlags>
58 inline constexpr std::enable_if_t<Internal::IsAllowedAsFlags<TFlags>,
bool> AnyFlagsActive(TFlags source, TFlags test)
60 return (source & test) !=
static_cast<TFlags
>(0);
64 template<
class TFlags>
65 inline constexpr std::enable_if_t<Internal::IsAllowedAsFlags<TFlags>,
bool> AllFlagsActive(TFlags source, TFlags test)
67 return (source & test) == test;
71 template<
class TFlags>
72 inline constexpr std::enable_if_t<Internal::IsAllowedAsFlags<TFlags>, TFlags> RemoveFlags(TFlags source, TFlags remove)
74 return source & ~remove;