11#pragma once
22
33#include < stdx/compiler.hpp>
4- #include < stdx/ct_string.hpp>
5- #include < stdx/utility.hpp>
4+ #include < stdx/env.hpp>
65
7- #include < boost/mp11/algorithm.hpp>
8-
9- namespace logging {
10- template <auto Query, auto Value> struct prop {
11- [[nodiscard]] CONSTEVAL static auto query (decltype (Query)) noexcept {
12- return Value;
13- }
14- };
15-
16- namespace detail {
17- template <typename Q, typename Env>
18- concept valid_query_for = requires { Env::query (Q{}); };
19-
20- template <typename Q, typename ... Envs>
21- concept valid_query_over = (... or valid_query_for<Q, Envs>);
22-
23- template <typename Q> struct has_query {
24- template <typename Env>
25- using fn = std::bool_constant<valid_query_for<Q, Env>>;
26- };
27- } // namespace detail
28-
29- template <typename ... Envs> struct env {
30- template <detail::valid_query_over<Envs...> Q>
31- CONSTEVAL static auto query (Q) noexcept {
32- using I = boost::mp11::mp_find_if_q<boost::mp11::mp_list<Envs...>,
33- detail::has_query<Q>>;
34- using E = boost::mp11::mp_at<boost::mp11::mp_list<Envs...>, I>;
35- return Q{}(E{});
36- }
37- };
38-
39- namespace detail {
40- template <typename T> struct autowrap {
41- // NOLINTNEXTLINE(google-explicit-constructor)
42- CONSTEVAL autowrap (T t) : value(t) {}
43- T value;
44- };
45-
46- // NOLINTNEXTLINE(modernize-avoid-c-arrays)
47- template <std::size_t N> using str_lit_t = char const (&)[N];
48-
49- template <std::size_t N> struct autowrap <str_lit_t <N>> {
50- // NOLINTNEXTLINE(google-explicit-constructor)
51- CONSTEVAL autowrap (str_lit_t <N> str) : value(str) {}
52- stdx::ct_string<N> value;
53- };
54-
55- template <typename T> autowrap (T) -> autowrap<T>;
56- template <std::size_t N> autowrap (str_lit_t <N>) -> autowrap<str_lit_t<N>>;
57-
58- template <auto V> struct wrap {
59- constexpr static auto value = V;
60- };
61-
62- template <typename > struct for_each_pair ;
63- template <std::size_t ... Is> struct for_each_pair <std::index_sequence<Is...>> {
64- template <auto ... Args>
65- using type = env<
66- prop<boost::mp11::mp_at_c<boost::mp11::mp_list<wrap<Args>...>,
67- 2 * Is>::value.value,
68- stdx::ct<boost::mp11::mp_at_c<boost::mp11::mp_list<wrap<Args>...>,
69- (2 * Is) + 1 >::value.value>()>...>;
70- };
71- } // namespace detail
72-
73- template <typename Env = env<>>
74- constexpr auto make_env = []<detail::autowrap... Args> {
75- using new_env_t = typename detail::for_each_pair<
76- std::make_index_sequence<sizeof ...(Args) / 2 >>::template type<Args...>;
77- return boost::mp11::mp_append<new_env_t , Env>{};
78- };
79-
80- template <typename Env, detail::autowrap... Args>
81- using extend_env_t = decltype (make_env<Env>.template operator ()<Args...>());
82-
83- template <detail::autowrap... Args>
84- using make_env_t = extend_env_t <env<>, Args...>;
85- } // namespace logging
86-
87- using cib_log_env_t = logging::env<>;
6+ using cib_log_env_t = stdx::env<>;
887
898// NOLINTBEGIN(cppcoreguidelines-macro-usage)
909
@@ -96,7 +15,7 @@ using cib_log_env_t = logging::env<>;
9615
9716#define CIB_LOG_ENV_DECL (...) \
9817 [[maybe_unused]] typedef decltype ([] { \
99- return logging ::extend_env_t <cib_log_env_t , __VA_ARGS__>{}; \
18+ return stdx ::extend_env_t <cib_log_env_t , __VA_ARGS__>{}; \
10019 }()) cib_log_env_t
10120
10221#define CIB_LOG_ENV (...) \
0 commit comments