Skip to content

Commit 494e03f

Browse files
authored
Merge pull request #700 from elbeno/move-env
Use `stdx::env` instead of `logging::env`
2 parents 45052f1 + 329167a commit 494e03f

21 files changed

+57
-136
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ include(cmake/string_catalog.cmake)
2525
add_versioned_package("gh:boostorg/mp11#boost-1.83.0")
2626
fmt_recipe(11.1.3)
2727
add_versioned_package("gh:intel/cpp-baremetal-concurrency#7c5b26c")
28-
add_versioned_package("gh:intel/cpp-std-extensions#37cc9c5")
28+
add_versioned_package("gh:intel/cpp-std-extensions#ec95cd6")
2929
add_versioned_package("gh:intel/cpp-baremetal-senders-and-receivers#73d95bc")
3030

3131
set(GEN_STR_CATALOG

include/flow/log.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace flow {
1111
using default_log_env =
12-
logging::make_env_t<logging::get_level, logging::level::TRACE>;
12+
stdx::make_env_t<logging::get_level, logging::level::TRACE>;
1313
template <stdx::ct_string, typename...>
1414
constexpr auto log_env = default_log_env{};
1515

include/interrupt/dynamic_controller.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#pragma once
22

3-
#include <conc/concurrency.hpp>
4-
53
#include <stdx/compiler.hpp>
64
#include <stdx/tuple.hpp>
75
#include <stdx/tuple_algorithms.hpp>
86
#include <stdx/type_traits.hpp>
97

8+
#include <conc/concurrency.hpp>
9+
1010
#include <boost/mp11/algorithm.hpp>
1111
#include <boost/mp11/list.hpp>
1212

include/log/catalog/mipi_builder.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ struct default_builder {
132132
return std::forward<T>(t).query(*this);
133133
}
134134

135-
CONSTEVAL auto operator()(auto &&) const {
136-
return stdx::ct<default_builder{}>();
137-
}
135+
CONSTEVAL auto operator()(auto &&) const { return default_builder{}; }
138136
} get_builder;
139137
} // namespace logging::mipi

include/log/catalog/mipi_encoder.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22

3-
#include <conc/concurrency.hpp>
43
#include <log/catalog/catalog.hpp>
54
#include <log/catalog/mipi_builder.hpp>
65
#include <log/catalog/mipi_messages.hpp>
@@ -13,6 +12,8 @@
1312
#include <stdx/tuple.hpp>
1413
#include <stdx/utility.hpp>
1514

15+
#include <conc/concurrency.hpp>
16+
1617
#include <algorithm>
1718
#include <concepts>
1819
#include <cstdint>
@@ -49,11 +50,10 @@ template <typename TDestinations> struct log_handler {
4950

5051
template <typename Env, typename Msg> auto log_msg(Msg msg) -> void {
5152
msg.apply([&]<typename S, typename... Args>(S, Args... args) {
52-
constexpr auto L = stdx::to_underlying(get_level(Env{}).value);
53+
constexpr auto L = stdx::to_underlying(get_level(Env{}));
5354
using Message = decltype(detail::to_message<S, Args...>());
54-
using Module =
55-
decltype(detail::to_module<get_module(Env{}).value>());
56-
auto builder = get_builder(Env{}).value;
55+
using Module = decltype(detail::to_module<get_module(Env{})>());
56+
auto builder = get_builder(Env{});
5757
write(builder.template build<L>(catalog<Message>(),
5858
module<Module>(), args...));
5959
});

include/log/env.hpp

Lines changed: 3 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,9 @@
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(...) \

include/log/flavor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct default_flavor_t;
1818
}
1919

2020
CONSTEVAL auto operator()(auto &&) const {
21-
return stdx::ct<stdx::type_identity<default_flavor_t>{}>();
21+
return stdx::type_identity<default_flavor_t>{};
2222
}
2323
} get_flavor;
2424
} // namespace logging

include/log/fmt/logger.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ template <typename TDestinations> struct log_handler {
5050
stdx::for_each(
5151
[&](auto &out) {
5252
::fmt::format_to(out, "{:>8}us {} [{}]: ", currentTime,
53-
level_wrapper<get_level(Env{}).value>{},
54-
get_module(Env{}).value);
53+
level_wrapper<get_level(Env{})>{},
54+
get_module(Env{}));
5555
msg.apply(
5656
[&]<typename StringType>(StringType, auto const &...args) {
5757
::fmt::format_to(out, StringType::value, args...);

include/log/log.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ template <typename...> inline auto config = null::config{};
4040

4141
template <typename Env, typename... Ts>
4242
constexpr static auto get_config() -> auto & {
43-
using flavor_t = typename decltype(get_flavor(Env{}).value)::type;
43+
using flavor_t = typename decltype(get_flavor(Env{}))::type;
4444
if constexpr (std::same_as<flavor_t, default_flavor_t>) {
4545
return config<Ts...>;
4646
} else {
@@ -63,7 +63,7 @@ static auto log(TArgs &&...args) -> void {
6363

6464
#define CIB_LOG_WITH_LEVEL(LEVEL, MSG, ...) \
6565
logging::log< \
66-
logging::extend_env_t<cib_log_env_t, logging::get_level, LEVEL>>( \
66+
stdx::extend_env_t<cib_log_env_t, logging::get_level, LEVEL>>( \
6767
__FILE__, __LINE__, sc::format(MSG##_sc __VA_OPT__(, ) __VA_ARGS__))
6868

6969
#define CIB_TRACE(...) \
@@ -109,7 +109,7 @@ template <typename Env, typename... Ts> static auto log_version() -> void {
109109
} // namespace logging
110110

111111
#define CIB_LOG_V(FLAVOR) \
112-
logging::log_version<logging::extend_env_t< \
112+
logging::log_version<stdx::extend_env_t< \
113113
cib_log_env_t, logging::get_flavor, stdx::type_identity<FLAVOR>{}>>()
114114
#define CIB_LOG_VERSION() CIB_LOG_V(logging::default_flavor_t)
115115

include/log/module.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace logging {
1818

1919
CONSTEVAL auto operator()(auto &&) const {
2020
using namespace stdx::literals;
21-
return "default"_ctst;
21+
return "default"_cts;
2222
}
2323
} get_module;
2424
} // namespace logging

0 commit comments

Comments
 (0)