From 8da654392d91d7c77243d9d093b83a9da4a6c637 Mon Sep 17 00:00:00 2001 From: Ben Deane Date: Thu, 27 Mar 2025 09:36:47 -0600 Subject: [PATCH] :fire: Remove sc from log, msg and match libraries Problem: - `sc` is superseded by stdx::ct_string functionality. Solution: - Remove dependency on `sc` for some libraries. Note: - For now, the flow library still uses `sc`. --- CMakeLists.txt | 7 ++- docs/intro.adoc | 13 +++-- include/flow/impl.hpp | 14 +++--- include/flow/step.hpp | 1 + include/log/catalog/encoder.hpp | 18 +++---- include/log/fmt/logger.hpp | 13 ++--- include/log/log.hpp | 25 +++++----- include/match/and.hpp | 3 +- include/match/bin_op.hpp | 10 ++-- include/match/concepts.hpp | 6 +-- include/match/constant.hpp | 13 +++-- include/match/not.hpp | 7 ++- include/match/or.hpp | 3 +- include/match/predicate.hpp | 3 +- include/msg/callback.hpp | 8 ++-- include/msg/detail/indexed_builder_common.hpp | 1 - include/msg/detail/indexed_handler_common.hpp | 3 +- include/msg/field.hpp | 18 ++++--- include/msg/field_matchers.hpp | 30 ++++++------ include/msg/handler.hpp | 4 +- include/msg/message.hpp | 47 +++++++++---------- test/log/catalog1_lib.cpp | 19 +++++--- test/log/catalog2a_lib.cpp | 6 ++- test/log/catalog2b_lib.cpp | 4 +- test/log/encoder.cpp | 17 +++---- test/log/fmt_logger.cpp | 3 +- test/log/level.cpp | 4 +- test/log/log.cpp | 4 +- test/log/module_id.cpp | 1 - test/match/and.cpp | 32 +++++++------ test/match/constant.cpp | 12 +++-- test/match/not.cpp | 10 ++-- test/match/or.cpp | 28 ++++++----- test/match/predicate.cpp | 8 +++- test/match/test_matcher.hpp | 33 ++++++++----- test/msg/callback.cpp | 7 ++- test/msg/indexed_callback.cpp | 1 - 37 files changed, 233 insertions(+), 203 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e96d8e4c..e3499288 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,7 @@ target_sources( add_library(cib_match INTERFACE) target_compile_features(cib_match INTERFACE cxx_std_20) -target_link_libraries_system(cib_match INTERFACE cib_sc stdx) +target_link_libraries_system(cib_match INTERFACE stdx) target_sources( cib_match @@ -79,7 +79,7 @@ target_sources( add_library(cib_interrupt INTERFACE) target_compile_features(cib_interrupt INTERFACE cxx_std_20) -target_link_libraries_system(cib_interrupt INTERFACE cib_sc concurrency stdx) +target_link_libraries_system(cib_interrupt INTERFACE concurrency stdx) target_sources( cib_interrupt @@ -123,7 +123,7 @@ target_sources( add_library(cib_log INTERFACE) target_compile_features(cib_log INTERFACE cxx_std_20) -target_link_libraries_system(cib_log INTERFACE cib_sc stdx) +target_link_libraries_system(cib_log INTERFACE stdx) target_sources( cib_log @@ -149,7 +149,6 @@ target_link_libraries_system( cib_log cib_lookup cib_match - cib_sc stdx) target_sources( diff --git a/docs/intro.adoc b/docs/intro.adoc index 2e657ca5..6aa39b65 100644 --- a/docs/intro.adoc +++ b/docs/intro.adoc @@ -57,18 +57,16 @@ library that contains all the functionality. [mermaid, format="svg"] ---- flowchart BT - sc(cib_sc) nexus(cib_nexus) + sc(cib_sc) + log(cib_log) + match(cib_match) lookup(cib_lookup) flow(cib_flow) --> nexus + flow --> sc flow --> log - interrupt(cib_interrupt) --> sc - match(cib_match) --> sc - log(cib_log) --> sc - - log_fmt(cib_log_fmt) --> log msg(cib_msg) --> log & match msg --> lookup @@ -76,5 +74,6 @@ flowchart BT log_binary(cib_log_binary) --> msg seq(cib_seq) --> flow - cib --> interrupt & seq & log_fmt & log_binary + interrupt(cib_interrupt) + cib --> seq & log_fmt & log_binary & interrupt ---- diff --git a/include/flow/impl.hpp b/include/flow/impl.hpp index 47733ed4..3797e36f 100644 --- a/include/flow/impl.hpp +++ b/include/flow/impl.hpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -22,8 +23,8 @@ constexpr auto run_func() -> void { logging::log< decltype(get_log_env>())>( __FILE__, __LINE__, - sc::format("flow.{}({})"_sc, typename CTNode::type_t{}, - typename CTNode::name_t{})); + stdx::ct_format<"flow.{}({})">(stdx::cts_t{}, + stdx::cts_t{})); } typename CTNode::func_t{}(); } @@ -56,19 +57,18 @@ template struct inlined_func_list { __attribute__((flatten, always_inline)) auto operator()() const -> void { constexpr static bool loggingEnabled = not Name.empty(); - constexpr auto name = - stdx::ct_string_to_type(); - if constexpr (loggingEnabled) { logging::log())>( - __FILE__, __LINE__, sc::format("flow.start({})"_sc, name)); + __FILE__, __LINE__, + stdx::ct_format<"flow.start({})">(stdx::cts_t{})); } (FuncPtrs(), ...); if constexpr (loggingEnabled) { logging::log())>( - __FILE__, __LINE__, sc::format("flow.end({})"_sc, name)); + __FILE__, __LINE__, + stdx::ct_format<"flow.end({})">(stdx::cts_t{})); } } }; diff --git a/include/flow/step.hpp b/include/flow/step.hpp index 38db8959..c34ff995 100644 --- a/include/flow/step.hpp +++ b/include/flow/step.hpp @@ -24,6 +24,7 @@ struct ct_node { decltype(stdx::ct_string_to_type()); using func_t = F; + constexpr static auto ct_type = Type; constexpr static auto ct_name = Name; constexpr static auto identity = Identity; constexpr static auto condition = Cond{}; diff --git a/include/log/catalog/encoder.hpp b/include/log/catalog/encoder.hpp index 0357bfe0..2a49b64b 100644 --- a/include/log/catalog/encoder.hpp +++ b/include/log/catalog/encoder.hpp @@ -21,7 +21,7 @@ namespace logging::binary { namespace detail { template constexpr static auto to_message() { - constexpr auto s = S::value; + constexpr auto s = std::string_view{S::value}; using char_t = typename std::remove_cv_t::value_type; return [&](std::integer_sequence) { return sc::message< @@ -74,20 +74,22 @@ template log_writer(T) -> log_writer; template struct log_handler { template - auto log(FilenameStringType, LineNumberType, MsgType const &msg) -> void { - log_msg(msg); + typename LineNumberType, typename FmtResult> + auto log(FilenameStringType, LineNumberType, FmtResult const &fr) -> void { + log_msg(fr); } - template auto log_msg(Msg msg) -> void { - msg.apply([&](S, Args... args) { + template + auto log_msg(FmtResult const &fr) -> void { + fr.args.apply([&](Args &&...args) { auto builder = get_builder(Env{}); constexpr auto L = stdx::to_underlying(get_level(Env{})); using Message = typename decltype(builder)::template convert_args< - detail::to_message_t::template fn, Args...>; + detail::to_message_t::template fn, + std::remove_cvref_t...>; using Module = decltype(detail::to_module()); w(builder.template build(catalog(), module(), - args...)); + std::forward(args)...)); }); } diff --git a/include/log/fmt/logger.hpp b/include/log/fmt/logger.hpp index 5432d904..f57cc204 100644 --- a/include/log/fmt/logger.hpp +++ b/include/log/fmt/logger.hpp @@ -40,8 +40,8 @@ template struct log_handler { constexpr explicit log_handler(TDestinations &&ds) : dests{std::move(ds)} {} template - auto log(FilenameStringType, LineNumberType, MsgType const &msg) -> void { + typename LineNumberType, typename FmtResult> + auto log(FilenameStringType, LineNumberType, FmtResult const &fr) -> void { auto const currentTime = std::chrono::duration_cast( std::chrono::steady_clock::now() - start_time) @@ -52,10 +52,11 @@ template struct log_handler { ::fmt::format_to(out, "{:>8}us {} [{}]: ", currentTime, level_wrapper{}, get_module(Env{})); - msg.apply( - [&](StringType, auto const &...args) { - ::fmt::format_to(out, StringType::value, args...); - }); + constexpr auto fmtstr = + std::string_view{decltype(fr.str)::value}; + fr.args.apply([&](auto const &...args) { + ::fmt::format_to(out, fmtstr, args...); + }); *out = '\n'; }, dests); diff --git a/include/log/log.hpp b/include/log/log.hpp index e30355cd..d96b53c5 100644 --- a/include/log/log.hpp +++ b/include/log/log.hpp @@ -4,10 +4,9 @@ #include #include #include -#include -#include #include +#include #include #include #include @@ -58,13 +57,13 @@ static auto log(TArgs &&...args) -> void { // NOLINTBEGIN(cppcoreguidelines-macro-usage) #define CIB_LOG(MSG, ...) \ - logging::log( \ - __FILE__, __LINE__, sc::format(MSG##_sc __VA_OPT__(, ) __VA_ARGS__)) + logging::log(__FILE__, __LINE__, \ + stdx::ct_format(__VA_ARGS__)) #define CIB_LOG_WITH_LEVEL(LEVEL, MSG, ...) \ logging::log< \ stdx::extend_env_t>( \ - __FILE__, __LINE__, sc::format(MSG##_sc __VA_OPT__(, ) __VA_ARGS__)) + __FILE__, __LINE__, stdx::ct_format(__VA_ARGS__)) #define CIB_TRACE(...) \ CIB_LOG_WITH_LEVEL(logging::level::TRACE __VA_OPT__(, ) __VA_ARGS__) @@ -76,14 +75,13 @@ static auto log(TArgs &&...args) -> void { CIB_LOG_WITH_LEVEL(logging::level::ERROR __VA_OPT__(, ) __VA_ARGS__) #define CIB_FATAL(MSG, ...) \ - [](auto &&str) { \ + [](auto &&s) { \ CIB_LOG_ENV(logging::get_level, logging::level::FATAL); \ - logging::log(__FILE__, __LINE__, str); \ - FWD(str).apply([](S s, Args... args) { \ - constexpr auto cts = stdx::ct_string_from_type(s); \ - stdx::panic(args...); \ + logging::log(__FILE__, __LINE__, s); \ + FWD(s).args.apply([](auto &&...args) { \ + stdx::panic(FWD(args)...); \ }); \ - }(sc::format(MSG##_sc __VA_OPT__(, ) __VA_ARGS__)) + }(stdx::ct_format(__VA_ARGS__)) #define CIB_ASSERT(expr) \ ((expr) ? void(0) : CIB_FATAL("Assertion failure: " #expr)) @@ -102,9 +100,8 @@ template static auto log_version() -> void { CIB_LOG_ENV(logging::get_level, logging::level::MAX); l_cfg.logger.template log( "", 0, - sc::format("Version: {} ({})"_sc, sc::uint_, - stdx::ct_string_to_type())); + stdx::ct_format<"Version: {} ({})">( + CX_VALUE(v_cfg.build_id), CX_VALUE(v_cfg.version_string))); } } } // namespace logging diff --git a/include/match/and.hpp b/include/match/and.hpp index d30915a7..c0ac55ab 100644 --- a/include/match/and.hpp +++ b/include/match/and.hpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include @@ -15,7 +14,7 @@ namespace match { template struct or_t; -template struct and_t : bin_op_t { +template struct and_t : bin_op_t { [[nodiscard]] constexpr auto operator()(auto const &event) const -> bool { return this->lhs(event) and this->rhs(event); } diff --git a/include/match/bin_op.hpp b/include/match/bin_op.hpp index 7e2f897a..d18298d1 100644 --- a/include/match/bin_op.hpp +++ b/include/match/bin_op.hpp @@ -4,8 +4,8 @@ #include #include #include -#include +#include #include #include @@ -32,16 +32,16 @@ struct bin_op_t { private: [[nodiscard]] constexpr auto form_description(auto const &f) const { + using namespace stdx::literals; auto const desc = [&](M const &m) { if constexpr (stdx::is_specialization_of_v) { return f(m); } else { - return "("_sc + f(m) + ")"_sc; + return "("_ctst + f(m) + ")"_ctst; } }; - return desc(lhs) + - stdx::ct_string_to_type() + - desc(rhs); + return stdx::ct_format<"{} {} {}">(desc(lhs), stdx::cts_t{}, + desc(rhs)); } }; diff --git a/include/match/concepts.hpp b/include/match/concepts.hpp index 250f2e76..3b88151d 100644 --- a/include/match/concepts.hpp +++ b/include/match/concepts.hpp @@ -1,7 +1,5 @@ #pragma once -#include - #include #include @@ -12,7 +10,7 @@ concept matcher = requires { typename std::remove_cvref_t::is_matcher; }; template concept matcher_for = matcher and requires(T const &t, Event const &e) { { t(e) } -> std::convertible_to; - { t.describe() } -> sc::sc_like; - { t.describe_match(e) } -> sc::sc_like; + t.describe(); + t.describe_match(e); }; } // namespace match diff --git a/include/match/constant.hpp b/include/match/constant.hpp index 88018fb0..271cd9c8 100644 --- a/include/match/constant.hpp +++ b/include/match/constant.hpp @@ -3,7 +3,8 @@ #include #include #include -#include + +#include // NOTE: the implication overloads in this file are crafted to be high priority, // to avoid ambiguity. Hence always_t and never_t define friend overloads that @@ -17,7 +18,10 @@ struct always_t { [[nodiscard]] constexpr auto operator()(auto const &) const -> bool { return true; } - [[nodiscard]] constexpr static auto describe() { return "true"_sc; } + [[nodiscard]] constexpr static auto describe() { + using namespace stdx::literals; + return "true"_ctst; + } [[nodiscard]] constexpr static auto describe_match(auto const &) { return describe(); } @@ -35,7 +39,10 @@ struct never_t { [[nodiscard]] constexpr auto operator()(auto const &) const -> bool { return false; } - [[nodiscard]] constexpr static auto describe() { return "false"_sc; } + [[nodiscard]] constexpr static auto describe() { + using namespace stdx::literals; + return "false"_ctst; + } [[nodiscard]] constexpr static auto describe_match(auto const &) { return describe(); } diff --git a/include/match/not.hpp b/include/match/not.hpp index 25922909..98b251f5 100644 --- a/include/match/not.hpp +++ b/include/match/not.hpp @@ -6,9 +6,8 @@ #include #include #include -#include -#include +#include #include #include @@ -26,11 +25,11 @@ template struct not_t { } [[nodiscard]] constexpr auto describe() const { - return format("not ({})"_sc, m.describe()); + return stdx::ct_format<"not ({})">(m.describe()); } [[nodiscard]] constexpr auto describe_match(auto const &event) const { - return format("not ({})"_sc, m.describe_match(event)); + return stdx::ct_format<"not ({})">(m.describe_match(event)); } private: diff --git a/include/match/or.hpp b/include/match/or.hpp index 5d49376f..eb86413f 100644 --- a/include/match/or.hpp +++ b/include/match/or.hpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include @@ -14,7 +13,7 @@ namespace match { template struct and_t; -template struct or_t : bin_op_t { +template struct or_t : bin_op_t { [[nodiscard]] constexpr auto operator()(auto const &event) const -> bool { return this->lhs(event) or this->rhs(event); } diff --git a/include/match/predicate.hpp b/include/match/predicate.hpp index 903e971c..09bc07f5 100644 --- a/include/match/predicate.hpp +++ b/include/match/predicate.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include @@ -24,7 +23,7 @@ template struct predicate_t { } [[nodiscard]] constexpr static auto describe() { - return stdx::ct_string_to_type(); + return stdx::cts_t{}; } [[nodiscard]] constexpr static auto describe_match(auto const &) { diff --git a/include/msg/callback.hpp b/include/msg/callback.hpp index a1f1c245..03aa8358 100644 --- a/include/msg/callback.hpp +++ b/include/msg/callback.hpp @@ -34,9 +34,8 @@ struct callback { CIB_APPEND_LOG_ENV(typename Msg::env_t); CIB_LOG("Incoming message matched [{}], because [{}]{}, executing " "callback", - stdx::ct_string_to_type(), - matcher.describe(), - stdx::ct_string_to_type()); + stdx::cts_t{}, matcher.describe(), + stdx::cts_t{}); msg::call_with_message(callable, data, std::forward(args)...); return true; @@ -49,8 +48,7 @@ struct callback { { CIB_APPEND_LOG_ENV(typename Msg::env_t); CIB_LOG( - " {} - F:({})", - stdx::ct_string_to_type(), + " {} - F:({})", stdx::cts_t{}, msg::call_with_message( [&](T &&t) -> decltype(matcher.describe_match( std::forward(t))) { diff --git a/include/msg/detail/indexed_builder_common.hpp b/include/msg/detail/indexed_builder_common.hpp index 1aee6f57..f342f1a5 100644 --- a/include/msg/detail/indexed_builder_common.hpp +++ b/include/msg/detail/indexed_builder_common.hpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include diff --git a/include/msg/detail/indexed_handler_common.hpp b/include/msg/detail/indexed_handler_common.hpp index 5b0eb835..81a0f096 100644 --- a/include/msg/detail/indexed_handler_common.hpp +++ b/include/msg/detail/indexed_handler_common.hpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -58,7 +59,7 @@ struct indexed_handler : handler_interface { if (not handled) { CIB_ERROR( "None of the registered callbacks ({}) claimed this message.", - sc::uint_>); + stdx::ct>()); } return handled; } diff --git a/include/msg/field.hpp b/include/msg/field.hpp index 068a9740..1b287715 100644 --- a/include/msg/field.hpp +++ b/include/msg/field.hpp @@ -3,10 +3,10 @@ #include #include #include -#include #include #include +#include #include #include #include @@ -65,10 +65,10 @@ concept field_locator_for = field_extractor_for and field_inserter_for; namespace detail { -template +template struct field_spec_t { using type = T; - using name_t = Name; + using name_t = stdx::cts_t; constexpr static name_t name{}; constexpr static auto size = BitSize; @@ -386,7 +386,7 @@ concept is_mutable_value = requires { typename T::is_mutable_t; }; template concept compatible_with_default = D::template is_compatible_value; -template +template struct field_id_t {}; template struct sort_key_t { @@ -394,7 +394,7 @@ template struct sort_key_t { }; template <> struct sort_key_t<> {}; -template , match::matcher M = match::always_t, at... Ats> requires std::is_trivially_copyable_v @@ -414,7 +414,7 @@ class field_t : public field_spec_t>, "Field size is smaller than sum of locations!"); public: - using name_t = Name; + using name_t = stdx::cts_t; using field_id = field_id_t; using value_type = T; using matcher_t = M; @@ -450,7 +450,7 @@ class field_t : public field_spec_t>, } [[nodiscard]] constexpr static auto describe(value_type v) { - return format("{}: 0x{:x}"_sc, spec_t::name, v); + return stdx::ct_format<"{}: 0x{:x}">(spec_t::name, v); } constexpr static auto can_hold(value_type v) -> bool { @@ -538,7 +538,5 @@ class field_t : public field_spec_t>, template , match::matcher M = match::always_t> -using field = detail::field_t< - decltype(stdx::ct_string_to_type()), T, Default, - M>; +using field = detail::field_t; } // namespace msg diff --git a/include/msg/field_matchers.hpp b/include/msg/field_matchers.hpp index 695a75c7..81319759 100644 --- a/include/msg/field_matchers.hpp +++ b/include/msg/field_matchers.hpp @@ -1,9 +1,10 @@ #pragma once #include -#include #include +#include +#include #include #include #include @@ -113,18 +114,19 @@ template constexpr auto inverse_op() { } template constexpr auto to_string() { + using namespace stdx::literals; if constexpr (std::same_as>) { - return "<"_sc; + return "<"_ctst; } else if constexpr (std::same_as>) { - return "<="_sc; + return "<="_ctst; } else if constexpr (std::same_as>) { - return ">"_sc; + return ">"_ctst; } else if constexpr (std::same_as>) { - return ">="_sc; + return ">="_ctst; } else if constexpr (std::same_as>) { - return "=="_sc; + return "=="_ctst; } else if constexpr (std::same_as>) { - return "!="_sc; + return "!="_ctst; } } } // namespace detail @@ -139,17 +141,17 @@ struct rel_matcher_t { } [[nodiscard]] constexpr auto describe() const { - return format("{} {} 0x{:x}"_sc, Field::name, - detail::to_string(), - sc::uint_(ExpectedValue)>); + return stdx::ct_format<"{} {} 0x{:x}">( + Field::name, detail::to_string(), + stdx::ct(ExpectedValue)>()); } template [[nodiscard]] constexpr auto describe_match(MsgType const &msg) const { - return format("{} (0x{:x}) {} 0x{:x}"_sc, Field::name, - static_cast(extract_field(msg)), - detail::to_string(), - sc::uint_(ExpectedValue)>); + return stdx::ct_format<"{} (0x{:x}) {} 0x{:x}">( + Field::name, static_cast(extract_field(msg)), + detail::to_string(), + stdx::ct(ExpectedValue)>()); } private: diff --git a/include/msg/handler.hpp b/include/msg/handler.hpp index 31029b63..0e5791f5 100644 --- a/include/msg/handler.hpp +++ b/include/msg/handler.hpp @@ -2,9 +2,9 @@ #include #include -#include #include +#include namespace msg { @@ -30,7 +30,7 @@ struct handler : handler_interface { if (!found_valid_callback) { CIB_ERROR( "None of the registered callbacks ({}) claimed this message:", - sc::uint_>); + stdx::ct>()); stdx::for_each([&](auto &callback) { callback.log_mismatch(msg); }, callbacks); } diff --git a/include/msg/message.hpp b/include/msg/message.hpp index ac8704fe..9679856d 100644 --- a/include/msg/message.hpp +++ b/include/msg/message.hpp @@ -4,10 +4,9 @@ #include #include #include -#include -#include #include +#include #include #include #include @@ -37,12 +36,12 @@ template concept matcher_maker = requires { typename T::is_matcher_maker; }; namespace detail { -template struct matching_name { +template struct matching_name { template - using fn = std::is_same; + using fn = std::bool_constant; }; -template struct matcher_maker { +template struct matcher_maker { using is_matcher_maker = void; template @@ -120,13 +119,13 @@ constexpr auto operator or(T, U) -> mm_or_t> { return {}; } -template struct field_value { - using name_t = Name; +template struct field_value { + using name_t = stdx::cts_t; T value; }; -template struct field_name { - using name_t = Name; +template struct field_name { + using name_t = stdx::cts_t; // NOLINTNEXTLINE(misc-unconventional-assign-operator) template constexpr auto operator=(T value) { @@ -173,12 +172,10 @@ template struct field_name { inline namespace literals { template constexpr auto operator""_field() { - using Name = decltype(stdx::ct_string_to_type()); - return detail::field_name{}; + return detail::field_name{}; } template constexpr auto operator""_f() { - using Name = decltype(stdx::ct_string_to_type()); - return detail::field_name{}; + return detail::field_name{}; } } // namespace literals @@ -212,9 +209,8 @@ template class msg_access { template constexpr static auto set1(R &&r, V v) -> void { - using Field = - std::remove_cvref_t( - FieldsTuple{}))>; + using Field = std::remove_cvref_t>( + FieldsTuple{}))>; check>(); Field::insert(std::forward(r), static_cast(v.value)); @@ -236,7 +232,7 @@ template class msg_access { } public: - template + template constexpr static auto set(R &&r, field_name...) -> void { (set_default(r), ...); } @@ -248,33 +244,32 @@ template class msg_access { template constexpr static auto set(R &&r, Fs...) -> void { - (set_default(r), ...); + (set_default>(r), ...); } - template + template constexpr static auto get(R &&r, field_name) { - return get(std::forward(r)); + return get>(std::forward(r)); } template constexpr static auto get(R &&r, F) { - return get(std::forward(r)); + return get>(std::forward(r)); } template [[nodiscard]] constexpr static auto describe(R &&r) { - using msg_name = - decltype(stdx::ct_string_to_type()); + using namespace stdx::literals; auto const descs = [&] { auto const field_descriptions = stdx::tuple{Fields::describe(Fields::extract(r))...}; if constexpr (sizeof...(Fields) > 0) { return field_descriptions.join( - [](auto lhs, auto rhs) { return lhs + ", "_sc + rhs; }); + [](auto lhs, auto rhs) { return lhs + ", "_ctst + rhs; }); } else { - return ""_sc; + return ""_ctst; } }(); - return format("{}({})"_sc, msg_name{}, descs); + return stdx::ct_format<"{}({})">(stdx::cts_t{}, descs); } using default_value_type = std::uint32_t; diff --git a/test/log/catalog1_lib.cpp b/test/log/catalog1_lib.cpp index 1e9ab23e..6447f2d0 100644 --- a/test/log/catalog1_lib.cpp +++ b/test/log/catalog1_lib.cpp @@ -2,6 +2,9 @@ #include +#include +#include + #include #include @@ -32,31 +35,33 @@ auto log_with_fixed_module_id() -> void; auto log_zero_args() -> void { auto cfg = logging::binary::config{test_log_args_destination{}}; - cfg.logger.log_msg("A string with no placeholders"_sc); + cfg.logger.log_msg( + stdx::ct_format<"A string with no placeholders">()); } auto log_one_ct_arg() -> void { + using namespace stdx::literals; auto cfg = logging::binary::config{test_log_args_destination{}}; cfg.logger.log_msg( - format("B string with {} placeholder"_sc, "one"_sc)); + stdx::ct_format<"B string with {} placeholder">("one"_ctst)); } auto log_one_32bit_rt_arg() -> void { auto cfg = logging::binary::config{test_log_args_destination{}}; cfg.logger.log_msg( - format("C1 string with {} placeholder"_sc, std::int32_t{1})); + stdx::ct_format<"C1 string with {} placeholder">(std::int32_t{1})); } auto log_one_64bit_rt_arg() -> void { auto cfg = logging::binary::config{test_log_args_destination{}}; cfg.logger.log_msg( - format("C2 string with {} placeholder"_sc, std::int64_t{1})); + stdx::ct_format<"C2 string with {} placeholder">(std::int64_t{1})); } auto log_one_formatted_rt_arg() -> void { auto cfg = logging::binary::config{test_log_args_destination{}}; cfg.logger.log_msg( - format("C3 string with {:08x} placeholder"_sc, std::int32_t{1})); + stdx::ct_format<"C3 string with {:08x} placeholder">(std::int32_t{1})); } auto log_with_non_default_module_id() -> void { @@ -64,7 +69,7 @@ auto log_with_non_default_module_id() -> void { logging::get_module, "not default") { auto cfg = logging::binary::config{test_log_args_destination{}}; cfg.logger.log_msg( - format("ModuleID string with {} placeholder"_sc, 1)); + stdx::ct_format<"ModuleID string with {} placeholder">(1)); } } @@ -73,6 +78,6 @@ auto log_with_fixed_module_id() -> void { logging::get_module, "fixed") { auto cfg = logging::binary::config{test_log_args_destination{}}; cfg.logger.log_msg( - format("Fixed ModuleID string with {} placeholder"_sc, 1)); + stdx::ct_format<"Fixed ModuleID string with {} placeholder">(1)); } } diff --git a/test/log/catalog2a_lib.cpp b/test/log/catalog2a_lib.cpp index c0ddddb8..3d7d9322 100644 --- a/test/log/catalog2a_lib.cpp +++ b/test/log/catalog2a_lib.cpp @@ -3,6 +3,8 @@ #include +#include + #include #include @@ -28,6 +30,6 @@ auto log_two_rt_args() -> void; auto log_two_rt_args() -> void { auto cfg = logging::binary::config{test_log_args_destination{}}; cfg.logger.log_msg( - format("D string with {} and {} placeholder"_sc, std::uint32_t{1}, - std::int64_t{2})); + stdx::ct_format<"D string with {} and {} placeholder">( + std::uint32_t{1}, std::int64_t{2})); } diff --git a/test/log/catalog2b_lib.cpp b/test/log/catalog2b_lib.cpp index 0effa9e9..4f4cebb3 100644 --- a/test/log/catalog2b_lib.cpp +++ b/test/log/catalog2b_lib.cpp @@ -3,6 +3,8 @@ #include +#include + #include #include @@ -25,5 +27,5 @@ auto log_rt_enum_arg() -> void { auto cfg = logging::binary::config{test_log_args_destination{}}; using namespace ns; cfg.logger.log_msg( - format("E string with {} placeholder"_sc, E::value)); + stdx::ct_format<"E string with {} placeholder">(E::value)); } diff --git a/test/log/encoder.cpp b/test/log/encoder.cpp index 9cade2c9..ad61efcf 100644 --- a/test/log/encoder.cpp +++ b/test/log/encoder.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include @@ -164,7 +165,7 @@ TEST_CASE("log zero arguments", "[mipi]") { test_critical_section::count = 0; auto cfg = logging::binary::config{ test_log_args_destination{}}; - cfg.logger.log_msg("Hello"_sc); + cfg.logger.log_msg(stdx::ct_format<"Hello">()); CHECK(test_critical_section::count == 2); } @@ -173,7 +174,7 @@ TEST_CASE("log one 32-bit argument", "[mipi]") { test_critical_section::count = 0; auto cfg = logging::binary::config{ test_log_args_destination{}}; - cfg.logger.log_msg(format("{}"_sc, 17u)); + cfg.logger.log_msg(stdx::ct_format<"{}">(17u)); CHECK(test_critical_section::count == 2); } @@ -184,7 +185,7 @@ TEST_CASE("log one 64-bit argument", "[mipi]") { auto cfg = logging::binary::config{ test_log_args_destination{}}; - cfg.logger.log_msg(format("{}"_sc, x)); + cfg.logger.log_msg(stdx::ct_format<"{}">(x)); CHECK(test_critical_section::count == 2); } @@ -193,7 +194,7 @@ TEST_CASE("log two arguments", "[mipi]") { test_critical_section::count = 0; auto cfg = logging::binary::config{ test_log_args_destination{}}; - cfg.logger.log_msg(format("{} {}"_sc, 17u, 18u)); + cfg.logger.log_msg(stdx::ct_format<"{} {}">(17u, 18u)); CHECK(test_critical_section::count == 2); } @@ -204,7 +205,7 @@ TEST_CASE("log more than two arguments", "[mipi]") { auto cfg = logging::binary::config{ test_log_buf_destination{}}; - cfg.logger.log_msg(format("{} {} {}"_sc, 17u, 18u, 19u)); + cfg.logger.log_msg(stdx::ct_format<"{} {} {}">(17u, 18u, 19u)); CHECK(test_critical_section::count == 2); } { @@ -213,7 +214,7 @@ TEST_CASE("log more than two arguments", "[mipi]") { test_log_buf_destination{}}; cfg.logger.log_msg( - format("{} {} {} {}"_sc, 17u, 18u, 19u, 20u)); + stdx::ct_format<"{} {} {} {}">(17u, 18u, 19u, 20u)); CHECK(test_critical_section::count == 2); } } @@ -226,7 +227,7 @@ TEST_CASE("log to multiple destinations", "[mipi]") { test_log_args_destination{}, test_log_args_destination{}}; - cfg.logger.log_msg(format("{} {}"_sc, 17u, 18u)); + cfg.logger.log_msg(stdx::ct_format<"{} {}">(17u, 18u)); CHECK(test_critical_section::count == 4); CHECK(num_log_args_calls == 2); } @@ -312,6 +313,6 @@ TEST_CASE("log with overridden builder", "[mipi]") { auto cfg = logging::binary::config{ test_catalog_args_destination{}}; - cfg.logger.log_msg("Hello"_sc); + cfg.logger.log_msg(stdx::ct_format<"Hello">()); CHECK(num_catalog_args_calls == 1); } diff --git a/test/log/fmt_logger.cpp b/test/log/fmt_logger.cpp index 08451e11..eae43256 100644 --- a/test/log/fmt_logger.cpp +++ b/test/log/fmt_logger.cpp @@ -1,5 +1,6 @@ #include +#include #include #include #include @@ -166,7 +167,7 @@ inline auto logging::config = logging::log{}>>( \ - __FILE__, __LINE__, sc::format(MSG##_sc __VA_OPT__(, ) __VA_ARGS__)) + __FILE__, __LINE__, stdx::ct_format(__VA_ARGS__)) TEST_CASE("logging can be flavored", "[fmt_logger]") { buffer.clear(); diff --git a/test/log/level.cpp b/test/log/level.cpp index 4ce4902f..7a27f8a9 100644 --- a/test/log/level.cpp +++ b/test/log/level.cpp @@ -1,9 +1,9 @@ #include #include #include -#include #include +#include #include #include @@ -59,7 +59,7 @@ TEST_CASE("mipi logger works with custom level", "[level]") { log_calls = 0; CIB_LOG_ENV(logging::get_level, custom_level::THE_ONE_LEVEL); auto cfg = logging::binary::config{test_destination{}}; - cfg.logger.log_msg(sc::format("Hello {} {}"_sc, 17, 42)); + cfg.logger.log_msg(stdx::ct_format<"Hello {} {}">(17, 42)); CHECK(log_calls == 1); } diff --git a/test/log/log.cpp b/test/log/log.cpp index 082f31c3..62517fda 100644 --- a/test/log/log.cpp +++ b/test/log/log.cpp @@ -3,6 +3,7 @@ #include #include +#include #include @@ -74,10 +75,11 @@ TEST_CASE("CIB_FATAL calls compile-time panic", "[log]") { } TEST_CASE("CIB_FATAL pre-formats arguments passed to panic", "[log]") { + using namespace stdx::literals; reset_test_state(); expected_why = "Hello 42"; - CIB_FATAL("{} {}", "Hello"_sc, sc::int_<42>); + CIB_FATAL("{} {}", "Hello"_ctst, stdx::ct<42>()); CAPTURE(buffer); CHECK(buffer.find("Hello 42") != std::string::npos); CHECK(panicked); diff --git a/test/log/module_id.cpp b/test/log/module_id.cpp index e75f6caf..11e6794d 100644 --- a/test/log/module_id.cpp +++ b/test/log/module_id.cpp @@ -1,5 +1,4 @@ #include -#include #include diff --git a/test/match/and.cpp b/test/match/and.cpp index 8fcac7fd..1783bf7d 100644 --- a/test/match/and.cpp +++ b/test/match/and.cpp @@ -1,8 +1,8 @@ #include "test_matcher.hpp" #include -#include -#include + +#include #include @@ -16,31 +16,33 @@ TEST_CASE("AND fulfils matcher concept", "[match and]") { TEST_CASE("AND describes itself", "[match and]") { constexpr auto e = test_m<0>{} and test_m<1>{}; - static_assert(e.describe() == format("({}) and ({})"_sc, - test_m<0>{}.describe(), - test_m<1>{}.describe())); + static_assert(e.describe() == + stdx::ct_format<"({}) and ({})">(test_m<0>{}.describe(), + test_m<1>{}.describe())); } TEST_CASE("AND description flattens", "[match and]") { constexpr auto e = test_m<0>{} and test_m<1>{} and test_m<2>{}; - static_assert(e.describe() == - format("({}) and ({}) and ({})"_sc, test_m<0>{}.describe(), - test_m<1>{}.describe(), test_m<2>{}.describe())); + static_assert(e.describe() == stdx::ct_format<"({}) and ({}) and ({})">( + test_m<0>{}.describe(), + test_m<1>{}.describe(), + test_m<2>{}.describe())); } TEST_CASE("AND describes a match", "[match and]") { constexpr auto e = test_m<0>{} and test_m<1>{}; - static_assert(e.describe_match(1) == format("({}) and ({})"_sc, - test_m<0>{}.describe_match(1), - test_m<1>{}.describe_match(1))); + static_assert(e.describe_match(1) == stdx::ct_format<"({}) and ({})">( + test_m<0>{}.describe_match(1), + test_m<1>{}.describe_match(1))); } TEST_CASE("AND match description flattens", "[match and]") { constexpr auto e = test_m<0>{} and test_m<1>{} and test_m<2>{}; - static_assert(e.describe_match(1) == format("({}) and ({}) and ({})"_sc, - test_m<0>{}.describe_match(1), - test_m<1>{}.describe_match(1), - test_m<2>{}.describe_match(1))); + static_assert(e.describe_match(1) == + stdx::ct_format<"({}) and ({}) and ({})">( + test_m<0>{}.describe_match(1), + test_m<1>{}.describe_match(1), + test_m<2>{}.describe_match(1))); } TEST_CASE("AND matches correctly", "[match and]") { diff --git a/test/match/constant.cpp b/test/match/constant.cpp index ed163841..2a01d7ab 100644 --- a/test/match/constant.cpp +++ b/test/match/constant.cpp @@ -1,5 +1,7 @@ #include +#include + #include TEST_CASE("constant fulfils matcher concepts", "[match constant]") { @@ -12,17 +14,19 @@ TEST_CASE("constant fulfils matcher concepts", "[match constant]") { } TEST_CASE("constant describes itself", "[match constant]") { + using namespace stdx::literals; using A = decltype(match::always); using N = decltype(match::never); - static_assert(A{}.describe() == "true"_sc); - static_assert(N{}.describe() == "false"_sc); + static_assert(A{}.describe() == "true"_ctst); + static_assert(N{}.describe() == "false"_ctst); } TEST_CASE("constant describes a match", "[match not]") { + using namespace stdx::literals; using A = decltype(match::always); using N = decltype(match::never); - static_assert(A{}.describe_match(0) == "true"_sc); - static_assert(N{}.describe_match(0) == "false"_sc); + static_assert(A{}.describe_match(0) == "true"_ctst); + static_assert(N{}.describe_match(0) == "false"_ctst); } TEST_CASE("constant matches correctly", "[match constant]") { diff --git a/test/match/not.cpp b/test/match/not.cpp index b397604b..3ff9479e 100644 --- a/test/match/not.cpp +++ b/test/match/not.cpp @@ -1,8 +1,8 @@ #include "test_matcher.hpp" #include -#include -#include + +#include #include @@ -17,13 +17,13 @@ TEST_CASE("NOT fulfils matcher concept", "[match not]") { TEST_CASE("NOT describes itself", "[match not]") { constexpr auto e = not test_matcher{}; static_assert(e.describe() == - format("not ({})"_sc, test_m<0>{}.describe())); + stdx::ct_format<"not ({})">(test_m<0>{}.describe())); } TEST_CASE("NOT describes a match", "[match not]") { constexpr auto e = not test_matcher{}; - static_assert(e.describe_match(1) == - format("not ({})"_sc, test_matcher{}.describe_match(1))); + static_assert(e.describe_match(1) == stdx::ct_format<"not ({})">( + test_matcher{}.describe_match(1))); } TEST_CASE("NOT matches correctly", "[match not]") { diff --git a/test/match/or.cpp b/test/match/or.cpp index ba72e70e..1ff0ac00 100644 --- a/test/match/or.cpp +++ b/test/match/or.cpp @@ -1,8 +1,8 @@ #include "test_matcher.hpp" #include -#include -#include + +#include #include @@ -16,29 +16,31 @@ TEST_CASE("OR fulfils matcher concept", "[match or]") { TEST_CASE("OR describes itself", "[match or]") { constexpr auto e = test_m<0>{} or test_m<1>{}; - static_assert(e.describe() == format("({}) or ({})"_sc, - test_m<0>{}.describe(), - test_m<1>{}.describe())); + static_assert(e.describe() == + stdx::ct_format<"({}) or ({})">(test_m<0>{}.describe(), + test_m<1>{}.describe())); } TEST_CASE("OR description flattens", "[match or]") { constexpr auto e = test_m<0>{} or test_m<1>{} or test_m<2>{}; - static_assert(e.describe() == - format("({}) or ({}) or ({})"_sc, test_m<0>{}.describe(), - test_m<1>{}.describe(), test_m<2>{}.describe())); + static_assert(e.describe() == stdx::ct_format<"({}) or ({}) or ({})">( + test_m<0>{}.describe(), + test_m<1>{}.describe(), + test_m<2>{}.describe())); } TEST_CASE("OR describes a match", "[match or]") { constexpr auto e = test_m<0>{} or test_m<1>{}; - static_assert(e.describe_match(1) == format("({}) or ({})"_sc, - test_m<0>{}.describe_match(1), - test_m<1>{}.describe_match(1))); + static_assert(e.describe_match(1) == stdx::ct_format<"({}) or ({})">( + test_m<0>{}.describe_match(1), + test_m<1>{}.describe_match(1))); } TEST_CASE("OR match description flattens", "[match or]") { constexpr auto e = test_m<0>{} or test_m<1>{} or test_m<2>{}; - static_assert(e.describe_match(1) == format("({}) or ({}) or ({})"_sc, - test_m<0>{}.describe_match(1), + static_assert( + e.describe_match(1) == + stdx::ct_format<"({}) or ({}) or ({})">(test_m<0>{}.describe_match(1), test_m<1>{}.describe_match(1), test_m<2>{}.describe_match(1))); } diff --git a/test/match/predicate.cpp b/test/match/predicate.cpp index 6efbba83..7d9f9149 100644 --- a/test/match/predicate.cpp +++ b/test/match/predicate.cpp @@ -1,6 +1,8 @@ #include #include +#include + #include TEST_CASE("predicate fulfils matcher concepts", "[match predicate]") { @@ -12,15 +14,17 @@ TEST_CASE("predicate fulfils matcher concepts", "[match predicate]") { } TEST_CASE("predicate describes itself", "[match predicate]") { + using namespace stdx::literals; [[maybe_unused]] constexpr auto p = match::predicate<"P">([](int) { return true; }); - static_assert(p.describe() == "P"_sc); + static_assert(p.describe() == "P"_ctst); } TEST_CASE("unnamed predicate", "[match predicate]") { + using namespace stdx::literals; [[maybe_unused]] constexpr auto p = match::predicate([](int) { return true; }); - static_assert(p.describe() == ""_sc); + static_assert(p.describe() == ""_ctst); } TEST_CASE("predicate matches correctly", "[match predicate]") { diff --git a/test/match/test_matcher.hpp b/test/match/test_matcher.hpp index bf204646..658a5426 100644 --- a/test/match/test_matcher.hpp +++ b/test/match/test_matcher.hpp @@ -3,8 +3,9 @@ #include #include #include -#include -#include + +#include +#include #include #include @@ -16,9 +17,12 @@ struct test_matcher { [[nodiscard]] constexpr auto operator()(int i) const -> bool { return i == 1; } - [[nodiscard]] constexpr static auto describe() { return "test"_sc; } + [[nodiscard]] constexpr static auto describe() { + using namespace stdx::literals; + return "test"_ctst; + } [[nodiscard]] constexpr auto describe_match(int i) const { - return format("{}({} == 1)"_sc, (*this)(i) ? 'T' : 'F', i); + return stdx::ct_format<"{}({} == 1)">((*this)(i) ? 'T' : 'F', i); } }; static_assert(match::matcher); @@ -40,15 +44,16 @@ template constexpr auto inverse_op() { return std::less{}; } } -template constexpr auto to_string() -> std::string_view { +template constexpr auto to_string() { + using namespace stdx::literals; if constexpr (std::same_as>) { - return "<"; + return "<"_ctst; } else if constexpr (std::same_as>) { - return "<="; + return "<="_ctst; } else if constexpr (std::same_as>) { - return ">"; + return ">"_ctst; } else if constexpr (std::same_as>) { - return ">="; + return ">="_ctst; } } } // namespace detail @@ -59,10 +64,14 @@ template struct rel_matcher { [[nodiscard]] constexpr auto operator()(int i) const -> bool { return RelOp{}(i, Value); } - [[nodiscard]] constexpr static auto describe() { return "test"_sc; } + [[nodiscard]] constexpr static auto describe() { + using namespace stdx::literals; + return "test"_ctst; + } [[nodiscard]] constexpr auto describe_match(int i) const { - return format("{}({} {} {})"_sc, (*this)(i) ? 'T' : 'F', i, - detail::to_string(), Value); + return stdx::ct_format<"{}({} {} {})">((*this)(i) ? 'T' : 'F', i, + detail::to_string(), + stdx::ct()); } private: diff --git a/test/msg/callback.cpp b/test/msg/callback.cpp index 9df176ba..56b89f06 100644 --- a/test/msg/callback.cpp +++ b/test/msg/callback.cpp @@ -3,6 +3,8 @@ #include #include +#include + #include #include @@ -31,7 +33,10 @@ constexpr struct custom_match_t { return true; } - [[nodiscard]] constexpr static auto describe() { return "custom"_sc; } + [[nodiscard]] constexpr static auto describe() { + using namespace stdx::literals; + return "custom"_ctst; + } [[nodiscard]] constexpr static auto describe_match(msg::owning) { return describe(); diff --git a/test/msg/indexed_callback.cpp b/test/msg/indexed_callback.cpp index ca9abb5d..672a69f7 100644 --- a/test/msg/indexed_callback.cpp +++ b/test/msg/indexed_callback.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include