di
0.1.0
Loading...
Searching...
No Matches
bitwise_enum.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
di/meta/core.h
"
4
#include "
di/meta/language.h
"
5
#include "
di/util/to_underlying.h
"
6
7
namespace
di::concepts
{
8
template
<
typename
T>
9
concept
BitwiseEnum
=
concepts::Enum<T>
&&
requires
(T& lvalue, T a) {
10
{ ~a } -> di::SameAs<T>;
11
{ a | a } -> di::SameAs<T>;
12
{ a & a } -> di::SameAs<T>;
13
{ a ^ a } -> di::SameAs<T>;
14
{ lvalue |= a } -> di::SameAs<T&>;
15
{ lvalue &= a } -> di::SameAs<T&>;
16
{ lvalue ^= a } -> di::SameAs<T&>;
17
};
18
}
19
20
#define DI_DEFINE_ENUM_BITWISE_OPERATIONS(Type) \
21
static_assert(::di::concepts::Enum<Type>); \
22
constexpr auto operator~(Type a)->Type { \
23
return static_cast<Type>(~::di::util::to_underlying(a)); \
24
} \
25
constexpr auto operator|(Type a, Type b)->Type { \
26
return static_cast<Type>(::di::util::to_underlying(a) | ::di::util::to_underlying(b)); \
27
} \
28
constexpr auto operator&(Type a, Type b)->Type { \
29
return static_cast<Type>(::di::util::to_underlying(a) & ::di::util::to_underlying(b)); \
30
} \
31
constexpr auto operator^(Type a, Type b)->Type { \
32
return static_cast<Type>(::di::util::to_underlying(a) ^ ::di::util::to_underlying(b)); \
33
} \
34
constexpr auto operator|=(Type& a, Type b)->Type& { \
35
return a = a | b; \
36
} \
37
constexpr auto operator&=(Type& a, Type b)->Type& { \
38
return a = a & b; \
39
} \
40
constexpr auto operator^=(Type& a, Type b)->Type& { \
41
return a = a ^ b; \
42
} \
43
constexpr auto operator!(Type a)->bool { \
44
return !::di::util::to_underlying(a); \
45
}
di::concepts::BitwiseEnum
Definition
bitwise_enum.h:9
di::concepts::Enum
Definition
language.h:259
core.h
language.h
di::concepts
Definition
any_storable.h:9
to_underlying.h
di
util
bitwise_enum.h
Generated by
1.13.2