di 0.1.0
Loading...
Searching...
No Matches
valid_enum_value.h
Go to the documentation of this file.
1#pragma once
2
5
6namespace di::reflection {
7namespace detail {
8 struct ValidEnumValueFunction {
9 template<concepts::ReflectableToEnumerators T>
10 requires(!concepts::BitwiseEnum<T>)
11 constexpr auto operator()(T value) const {
12 auto result = false;
14 [&](auto enumerator) {
15 if (enumerator.value == value) {
16 result = true;
17 }
18 },
19 reflection::reflect(value));
20 return result;
21 }
22
23 template<concepts::ReflectableToEnumerators T>
24 requires(concepts::BitwiseEnum<T>)
25 constexpr auto operator()(T value) const {
26 auto result = false;
28 [&](auto enumerator) {
29 if (enumerator.value == value) {
30 result = true;
31 }
32 },
33 reflection::reflect(value));
34 if (result) {
35 return true;
36 }
37
39 [&](auto enumerator) {
40 if ((value & enumerator.value) != T(0)) {
41 result = true;
42 }
43 value &= ~enumerator.value;
44 },
45 reflection::reflect(value));
46 return result && value == T(0);
47 }
48 };
49}
50
51constexpr inline auto valid_enum_value = detail::ValidEnumValueFunction {};
52}
53
54namespace di {
56}
constexpr auto value
Definition value.h:34
Definition atom.h:10
constexpr auto valid_enum_value
Definition valid_enum_value.h:51
constexpr auto enumerator
Definition enumerator.h:40
constexpr auto reflect
Definition reflect.h:47
Definition any_storable.h:9
constexpr void tuple_for_each(F &&function, Tup &&tuple)
Definition tuple_for_each.h:22