|
| 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 |
0 commit comments