Clingo
Loading...
Searching...
No Matches
enum.hh
1#pragma once
2
3#include <type_traits> // IWYU pragma: keep
4
5namespace CppClingo {
6
9
10// NOLINTBEGIN
11
18#define CLINGO_ENABLE_BITSET_ENUM(E, ...) \
19 [[nodiscard]] CLINGO_ENUM_OP(~, (E a), __VA_ARGS__)->E { \
20 return static_cast<E>(~static_cast<std::underlying_type_t<E>>(a)); \
21 } \
22 [[nodiscard]] CLINGO_ENUM_OP(|, (E a, E b), __VA_ARGS__)->E { \
23 return static_cast<E>(static_cast<std::underlying_type_t<E>>(a) | static_cast<std::underlying_type_t<E>>(b)); \
24 } \
25 CLINGO_ENUM_OP(|=, (E & a, E b), __VA_ARGS__)->E & { \
26 return a = a | b; \
27 } \
28 [[nodiscard]] CLINGO_ENUM_OP(&, (E a, E b), __VA_ARGS__)->E { \
29 return static_cast<E>(static_cast<std::underlying_type_t<E>>(a) & static_cast<std::underlying_type_t<E>>(b)); \
30 } \
31 CLINGO_ENUM_OP(&=, (E & a, E b), __VA_ARGS__)->E & { \
32 return a = a & b; \
33 } \
34 [[nodiscard]] CLINGO_ENUM_OP(-, (E a, E b), __VA_ARGS__)->E { \
35 return static_cast<E>(static_cast<std::underlying_type_t<E>>(a) & static_cast<std::underlying_type_t<E>>(~b)); \
36 } \
37 CLINGO_ENUM_OP(-=, (E & a, E b), __VA_ARGS__)->E & { \
38 return a = a - b; \
39 } \
40 [[nodiscard]] CLINGO_ENUM_OP(^, (E a, E b), __VA_ARGS__)->E { \
41 return static_cast<E>(static_cast<std::underlying_type_t<E>>(a) ^ static_cast<std::underlying_type_t<E>>(b)); \
42 } \
43 CLINGO_ENUM_OP(^=, (E & a, E b), __VA_ARGS__)->E & { \
44 return a = a ^ b; \
45 } \
46 [[nodiscard]] [[maybe_unused]] inline __VA_ARGS__ constexpr auto intersects(E a, E b) -> bool { \
47 return static_cast<std::underlying_type_t<E>>(a & b) != 0; \
48 } \
49 static_assert(std::is_enum_v<E>)
50
52#define CLINGO_ENUM_OP(op, arg, ...) [[maybe_unused]] inline __VA_ARGS__ constexpr auto operator op arg noexcept
53
54// NOLINTEND
55
57
58} // namespace CppClingo