|
2 | 2 | #include <concepts> |
3 | 3 | #include <type_traits> |
4 | 4 |
|
5 | | -export module mcpplibs.primitives.traits.underlying; |
| 5 | +export module mcpplibs.primitives.underlying.traits; |
6 | 6 |
|
7 | 7 | export namespace mcpplibs::primitives { |
8 | 8 |
|
@@ -39,38 +39,24 @@ enum class category { |
39 | 39 | }; |
40 | 40 |
|
41 | 41 | template <typename T> struct traits { |
42 | | - static constexpr bool enabled = false; |
43 | | -}; |
| 42 | + using value_type = void; |
| 43 | + using rep_type = void; |
44 | 44 |
|
45 | | -template <std_underlying_type T> struct traits<T> { |
46 | | - using value_type = std::remove_cv_t<T>; |
47 | | - using rep_type = value_type; |
| 45 | + static constexpr bool enabled = false; |
48 | 46 |
|
49 | | - static constexpr bool enabled = true; |
| 47 | + static constexpr auto kind = static_cast<category>(-1); |
50 | 48 |
|
51 | | - static constexpr category kind = [] { |
52 | | - if constexpr (std_bool<value_type>) { |
53 | | - return category::boolean; |
54 | | - } else if constexpr (std_char<value_type>) { |
55 | | - return category::character; |
56 | | - } else if constexpr (std_integer<value_type>) { |
57 | | - return category::integer; |
58 | | - } else { |
59 | | - return category::floating; |
60 | | - } |
61 | | - }(); |
| 49 | + template <typename U> static constexpr rep_type to_rep(U) noexcept {} |
62 | 50 |
|
63 | | - static constexpr rep_type to_rep(value_type value) noexcept { return value; } |
| 51 | + template <typename U> static constexpr value_type from_rep(U) noexcept {} |
64 | 52 |
|
65 | | - static constexpr value_type from_rep(rep_type value) noexcept { |
66 | | - return value; |
| 53 | + template <typename U> static constexpr bool is_valid_rep(U) noexcept { |
| 54 | + return false; |
67 | 55 | } |
68 | | - |
69 | | - static constexpr bool is_valid_rep(rep_type) noexcept { return true; } |
70 | 56 | }; |
71 | | -} // namespace underlying |
72 | 57 |
|
73 | | -} // namespace mcpplibs::primitives |
| 58 | +} // namespace underlying |
| 59 | +} |
74 | 60 |
|
75 | 61 | namespace mcpplibs::primitives::underlying::details { |
76 | 62 |
|
@@ -102,8 +88,7 @@ concept has_rep_bridge = |
102 | 88 |
|
103 | 89 | template <typename T> |
104 | 90 | concept has_std_rep_type = |
105 | | - has_rep_type<T> && |
106 | | - std_underlying_type<typename traits<std::remove_cv_t<T>>::rep_type>; |
| 91 | + has_rep_type<T> && std_underlying_type<typename traits<std::remove_cv_t<T>>::rep_type>; |
107 | 92 |
|
108 | 93 | template <std_underlying_type T> |
109 | 94 | consteval category category_of_std_underlying_type() { |
@@ -131,9 +116,11 @@ export namespace mcpplibs::primitives { |
131 | 116 |
|
132 | 117 | template <typename T> |
133 | 118 | concept underlying_type = |
134 | | - underlying::details::enabled<T> && underlying::details::has_category<T> && |
| 119 | + underlying::details::enabled<T> && |
| 120 | + underlying::details::has_category<T> && |
135 | 121 | underlying::details::has_rep_bridge<T> && |
136 | 122 | underlying::details::has_std_rep_type<T> && |
137 | 123 | underlying::details::has_consistent_category<T>; |
138 | 124 |
|
139 | 125 | } // namespace mcpplibs::primitives |
| 126 | + |
0 commit comments