Skip to content

Commit 4694dc2

Browse files
feat: Add policy
1 parent 9c5b311 commit 4694dc2

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

src/traits/policy.cppm

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
module;
2+
#include <type_traits>
3+
4+
export module mcpplibs.primitive.traits.policy;
5+
6+
export namespace mcpplibs::primitive {
7+
8+
namespace policy {
9+
10+
enum class category { value, type, error, concurrency };
11+
12+
template <typename P> struct traits {
13+
static constexpr bool enabled = false;
14+
static constexpr category kind = static_cast<category>(-1);
15+
};
16+
17+
struct checked_value {};
18+
struct unchecked_value {};
19+
20+
struct strict_type {};
21+
struct relaxed_type {};
22+
23+
struct throw_error {};
24+
struct expected_error {};
25+
26+
struct single_thread {};
27+
struct atomic {};
28+
29+
template <> struct traits<checked_value> {
30+
static constexpr bool enabled = true;
31+
static constexpr category kind = category::value;
32+
};
33+
34+
template <> struct traits<unchecked_value> {
35+
static constexpr bool enabled = true;
36+
static constexpr category kind = category::value;
37+
};
38+
39+
template <> struct traits<strict_type> {
40+
static constexpr bool enabled = true;
41+
static constexpr category kind = category::type;
42+
};
43+
44+
template <> struct traits<relaxed_type> {
45+
static constexpr bool enabled = true;
46+
static constexpr category kind = category::type;
47+
};
48+
49+
template <> struct traits<throw_error> {
50+
static constexpr bool enabled = true;
51+
static constexpr category kind = category::error;
52+
};
53+
54+
template <> struct traits<expected_error> {
55+
static constexpr bool enabled = true;
56+
static constexpr category kind = category::error;
57+
};
58+
59+
template <> struct traits<single_thread> {
60+
static constexpr bool enabled = true;
61+
static constexpr category kind = category::concurrency;
62+
};
63+
64+
template <> struct traits<atomic> {
65+
static constexpr bool enabled = true;
66+
static constexpr category kind = category::concurrency;
67+
};
68+
69+
template <typename P>
70+
concept policy_type = traits<P>::enabled;
71+
72+
struct default_policies {
73+
using value = unchecked_value;
74+
using type = relaxed_type;
75+
using error = throw_error;
76+
using concurrency = single_thread;
77+
};
78+
79+
} // namespace policy
80+
81+
} // namespace mcpplibs::primitive

src/traits/traits.cppm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ module;
33
export module mcpplibs.primitive.traits;
44

55
export import mcpplibs.primitive.traits.underlying;
6+
export import mcpplibs.primitive.traits.policy;

0 commit comments

Comments
 (0)