Skip to content

Commit ebfcee9

Browse files
refactor: Move underlying to a separate submodule
1 parent 4eae2a1 commit ebfcee9

File tree

3 files changed

+58
-28
lines changed

3 files changed

+58
-28
lines changed

src/underlying/impl.cppm

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module;
2+
#include <type_traits>
3+
4+
export module mcpplibs.primitives.underlying.impl;
5+
6+
import mcpplibs.primitives.underlying.traits;
7+
8+
export
9+
template <mcpplibs::primitives::std_underlying_type T>
10+
struct mcpplibs::primitives::underlying::traits<T> {
11+
using value_type = std::remove_cv_t<T>;
12+
using rep_type = value_type;
13+
14+
static constexpr bool enabled = true;
15+
16+
static constexpr category kind = [] {
17+
if constexpr (std_bool<value_type>) {
18+
return category::boolean;
19+
} else if constexpr (std_char<value_type>) {
20+
return category::character;
21+
} else if constexpr (std_integer<value_type>) {
22+
return category::integer;
23+
} else {
24+
return category::floating;
25+
}
26+
}();
27+
28+
static constexpr rep_type to_rep(value_type value) noexcept { return value; }
29+
30+
static constexpr value_type from_rep(rep_type value) noexcept {
31+
return value;
32+
}
33+
34+
static constexpr bool is_valid_rep(rep_type) noexcept { return true; }
35+
};
36+
37+
Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module;
22
#include <concepts>
33
#include <type_traits>
44

5-
export module mcpplibs.primitives.traits.underlying;
5+
export module mcpplibs.primitives.underlying.traits;
66

77
export namespace mcpplibs::primitives {
88

@@ -39,38 +39,24 @@ enum class category {
3939
};
4040

4141
template <typename T> struct traits {
42-
static constexpr bool enabled = false;
43-
};
42+
using value_type = void;
43+
using rep_type = void;
4444

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;
4846

49-
static constexpr bool enabled = true;
47+
static constexpr auto kind = static_cast<category>(-1);
5048

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 {}
6250

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 {}
6452

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;
6755
}
68-
69-
static constexpr bool is_valid_rep(rep_type) noexcept { return true; }
7056
};
71-
} // namespace underlying
7257

73-
} // namespace mcpplibs::primitives
58+
} // namespace underlying
59+
}
7460

7561
namespace mcpplibs::primitives::underlying::details {
7662

@@ -102,8 +88,7 @@ concept has_rep_bridge =
10288

10389
template <typename T>
10490
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>;
10792

10893
template <std_underlying_type T>
10994
consteval category category_of_std_underlying_type() {
@@ -131,9 +116,11 @@ export namespace mcpplibs::primitives {
131116

132117
template <typename T>
133118
concept underlying_type =
134-
underlying::details::enabled<T> && underlying::details::has_category<T> &&
119+
underlying::details::enabled<T> &&
120+
underlying::details::has_category<T> &&
135121
underlying::details::has_rep_bridge<T> &&
136122
underlying::details::has_std_rep_type<T> &&
137123
underlying::details::has_consistent_category<T>;
138124

139125
} // namespace mcpplibs::primitives
126+

src/underlying/underlying.cppm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module;
2+
3+
export module mcpplibs.primitives.underlying;
4+
5+
export import mcpplibs.primitives.underlying.traits;
6+
export import mcpplibs.primitives.underlying.impl;

0 commit comments

Comments
 (0)