5#ifndef MI_BASE_ENUM_UTIL_H
6#define MI_BASE_ENUM_UTIL_H
8#if (__cplusplus >= 201402L)
14#define MI_MAKE_ENUM_BITOPS_PAIR(Enum,OP) \
15MI_HOST_DEVICE_INLINE constexpr Enum operator OP(const Enum l, const Enum r) { \
16 using Basic = std::underlying_type_t<Enum>; \
17 return static_cast<Enum>(static_cast<Basic>(l) OP static_cast<Basic>(r)); } \
18MI_HOST_DEVICE_INLINE Enum& operator OP##=(Enum& l, const Enum r) { \
19 using Basic = std::underlying_type_t<Enum>; \
20 return reinterpret_cast<Enum&>(reinterpret_cast<Basic&>(l) OP##= static_cast<Basic>(r)); }
23#define MI_MAKE_ENUM_SHIFTOPS_PAIR(Enum,OP) \
24template <typename T, std::enable_if_t<std::is_integral<T>::value,bool> = true> \
25MI_HOST_DEVICE_INLINE constexpr Enum operator OP(const Enum e, const T s) { \
26 return static_cast<Enum>(static_cast<std::underlying_type_t<Enum>>(e) OP s); } \
27template <typename T, std::enable_if_t<std::is_integral<T>::value,bool> = true> \
28MI_HOST_DEVICE_INLINE constexpr Enum& operator OP##=(Enum& e, const T s) { \
29 return reinterpret_cast<Enum&>(reinterpret_cast<std::underlying_type_t<Enum>&>(e) OP##= s); }
35#define MI_MAKE_ENUM_BITOPS(Enum) \
36MI_MAKE_ENUM_BITOPS_PAIR(Enum,|) \
37MI_MAKE_ENUM_BITOPS_PAIR(Enum,&) \
38MI_MAKE_ENUM_BITOPS_PAIR(Enum,^) \
39MI_MAKE_ENUM_BITOPS_PAIR(Enum,+) \
40MI_MAKE_ENUM_BITOPS_PAIR(Enum,-) \
41MI_MAKE_ENUM_SHIFTOPS_PAIR(Enum,<<) \
42MI_MAKE_ENUM_SHIFTOPS_PAIR(Enum,>>) \
43MI_HOST_DEVICE_INLINE constexpr Enum operator ~(const Enum e) { \
44 return static_cast<Enum>(~static_cast<std::underlying_type_t<Enum>>(e)); }
49template <typename T, std::enable_if_t<std::is_enum<T>::value,
bool> =
true>
50constexpr auto to_underlying(
const T val) {
return std::underlying_type_t<T>(val); }
52template <typename T, std::enable_if_t<std::is_integral<T>::value,
bool> =
true>
53constexpr auto to_underlying(
const T val) {
return val; }
58#define MI_MAKE_ENUM_BITOPS(Enum)
Configuration of the Base API.
Common namespace for APIs of NVIDIA Advanced Rendering Center GmbH.
Definition: example_derivatives.dox:5