From 33395fa9ff6b473f1b771290b97c87f067b386c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Steffen=20Ga=C3=9Fmann?= Date: Wed, 26 Nov 2025 12:59:58 +0000 Subject: [PATCH] refactor: adapt to fmt v11 API changes --- libs/deeplog/CMakeLists.txt | 2 +- libs/deeplog/src/dlog_tests/test_utils.hpp | 1 - .../dplx/dlog/argument_transmorpher_fmt.hpp | 1 - .../src/dplx/dlog/core/strong_types.hpp | 2 +- .../src/dplx/dlog/detail/any_loggable_ref.hpp | 2 +- .../dplx/dlog/detail/system_error2_fmt.hpp | 16 ++--- .../dlog/detail/system_error2_fmt.test.cpp | 61 +++++++++++++++++++ .../src/dplx/dlog/record_container.hpp | 1 - libs/deeplog/src/dplx/dlog/source/log.hpp | 2 +- .../src/dlog_tui_tests/test_utils.hpp | 1 - 10 files changed, 71 insertions(+), 18 deletions(-) create mode 100644 libs/deeplog/src/dplx/dlog/detail/system_error2_fmt.test.cpp diff --git a/libs/deeplog/CMakeLists.txt b/libs/deeplog/CMakeLists.txt index a45bcd4..85ebf1c 100644 --- a/libs/deeplog/CMakeLists.txt +++ b/libs/deeplog/CMakeLists.txt @@ -111,6 +111,7 @@ dplx_target_sources(deeplog dlog/detail/any_loggable_ref dlog/detail/any_reified + dlog/detail/system_error2_fmt dlog/detail/workaround ) @@ -126,7 +127,6 @@ dplx_target_sources(deeplog dlog/macros.hpp dlog/detail/hex.hpp - dlog/detail/system_error2_fmt.hpp dlog/detail/utils.hpp dlog/detail/x_poly_types.inl diff --git a/libs/deeplog/src/dlog_tests/test_utils.hpp b/libs/deeplog/src/dlog_tests/test_utils.hpp index c8cf4bb..048da25 100644 --- a/libs/deeplog/src/dlog_tests/test_utils.hpp +++ b/libs/deeplog/src/dlog_tests/test_utils.hpp @@ -10,7 +10,6 @@ #include #include -#include #include #include diff --git a/libs/deeplog/src/dplx/dlog/argument_transmorpher_fmt.hpp b/libs/deeplog/src/dplx/dlog/argument_transmorpher_fmt.hpp index 3ffe5ea..503dc32 100644 --- a/libs/deeplog/src/dplx/dlog/argument_transmorpher_fmt.hpp +++ b/libs/deeplog/src/dplx/dlog/argument_transmorpher_fmt.hpp @@ -14,7 +14,6 @@ #include #include -#include #include #include diff --git a/libs/deeplog/src/dplx/dlog/core/strong_types.hpp b/libs/deeplog/src/dplx/dlog/core/strong_types.hpp index 0028380..5bd8e8a 100644 --- a/libs/deeplog/src/dplx/dlog/core/strong_types.hpp +++ b/libs/deeplog/src/dplx/dlog/core/strong_types.hpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include diff --git a/libs/deeplog/src/dplx/dlog/detail/any_loggable_ref.hpp b/libs/deeplog/src/dplx/dlog/detail/any_loggable_ref.hpp index 9fa1bef..6c2d433 100644 --- a/libs/deeplog/src/dplx/dlog/detail/any_loggable_ref.hpp +++ b/libs/deeplog/src/dplx/dlog/detail/any_loggable_ref.hpp @@ -9,7 +9,7 @@ #include -#include +#include #include #include diff --git a/libs/deeplog/src/dplx/dlog/detail/system_error2_fmt.hpp b/libs/deeplog/src/dplx/dlog/detail/system_error2_fmt.hpp index 34f52f6..207a010 100644 --- a/libs/deeplog/src/dplx/dlog/detail/system_error2_fmt.hpp +++ b/libs/deeplog/src/dplx/dlog/detail/system_error2_fmt.hpp @@ -1,5 +1,5 @@ -// Copyright Henrik Steffen Gaßmann 2023 +// Copyright Henrik Steffen Gaßmann 2023, 2025. // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE or copy at @@ -28,8 +28,8 @@ struct string_ref_formatter : private Formatter } template - auto format(status_code_domain::string_ref const &str, FormatContext &ctx) - -> typename FormatContext::iterator + auto format(status_code_domain::string_ref const &str, + FormatContext &ctx) const -> typename FormatContext::iterator { return base::format(StringView(str.data(), str.size()), ctx); } @@ -59,7 +59,7 @@ struct std::formatter +#include SYSTEM_ERROR2_NAMESPACE_BEGIN namespace detail @@ -92,7 +92,7 @@ struct trivial_status_code_view { system_error2::status_code const *code; - trivial_status_code_view() noexcept = default; + constexpr trivial_status_code_view() noexcept = default; DPLX_ATTR_FORCE_INLINE trivial_status_code_view(system_error2::status_code const &sc) @@ -105,15 +105,13 @@ struct reified_status_code std::uint64_t mDomainId{}; std::pmr::string mDomainName; std::pmr::string mMessage; - - reified_status_code() noexcept = default; }; struct trivial_system_code_view { system_error2::system_code const *code; - trivial_system_code_view() noexcept = default; + constexpr trivial_system_code_view() noexcept = default; DPLX_ATTR_FORCE_INLINE trivial_system_code_view(system_error2::system_code const &sc) @@ -127,8 +125,6 @@ struct reified_system_code std::uint64_t mRawValue{}; std::pmr::string mDomainName; std::pmr::string mMessage; - - reified_system_code() noexcept = default; }; } // namespace dplx::dlog::detail diff --git a/libs/deeplog/src/dplx/dlog/detail/system_error2_fmt.test.cpp b/libs/deeplog/src/dplx/dlog/detail/system_error2_fmt.test.cpp new file mode 100644 index 0000000..47e3128 --- /dev/null +++ b/libs/deeplog/src/dplx/dlog/detail/system_error2_fmt.test.cpp @@ -0,0 +1,61 @@ + +// Copyright Henrik S. Gaßmann 2025. +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +#include "dplx/dlog/detail/system_error2_fmt.hpp" + +#include + +#include "test_dir.hpp" +#include "test_utils.hpp" + +namespace dlog_tests +{ + +TEST_CASE("formats a static_code_domain::string_ref using fmt") +{ + using namespace dplx::dlog::detail; + constexpr char const helloWorld[] = "Hello, World!"; + + SYSTEM_ERROR2_NAMESPACE::status_code_domain::string_ref strRef{ + static_cast(helloWorld), sizeof(helloWorld) - 1}; + + auto const formatted = fmt::format("{}", strRef); + REQUIRE(formatted + == std::string_view{static_cast(helloWorld), + sizeof(helloWorld) - 1}); +} + +TEST_CASE("formats a reified_status_code using fmt") +{ + using namespace dplx::dlog::detail; + + reified_status_code code{ + .mDomainId = system_error2::generic_code::domain_type::get().id(), + .mDomainName = "example_domain", + .mMessage = "an example message", + }; + + auto const formatted = fmt::format("{}", code); + REQUIRE(formatted == "{example_domain: an example message}"); +} + +TEST_CASE("formats a reified_system_code using fmt") +{ + using namespace dplx::dlog::detail; + + reified_system_code code{ + .mDomainId = system_error2::generic_code::domain_type::get().id(), + .mRawValue = 0, + .mDomainName = "example_system_domain", + .mMessage = "a system error message", + }; + + auto const formatted = fmt::format("{}", code); + REQUIRE(formatted == "{example_system_domain: a system error message}"); +} + +} // namespace dlog_tests diff --git a/libs/deeplog/src/dplx/dlog/record_container.hpp b/libs/deeplog/src/dplx/dlog/record_container.hpp index 93731e2..f649879 100644 --- a/libs/deeplog/src/dplx/dlog/record_container.hpp +++ b/libs/deeplog/src/dplx/dlog/record_container.hpp @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/libs/deeplog/src/dplx/dlog/source/log.hpp b/libs/deeplog/src/dplx/dlog/source/log.hpp index ba075f8..fa8fedc 100644 --- a/libs/deeplog/src/dplx/dlog/source/log.hpp +++ b/libs/deeplog/src/dplx/dlog/source/log.hpp @@ -14,7 +14,7 @@ #include #endif -#include +#include #include #include diff --git a/libs/deeplog_tui/src/dlog_tui_tests/test_utils.hpp b/libs/deeplog_tui/src/dlog_tui_tests/test_utils.hpp index 43c68b6..5921123 100644 --- a/libs/deeplog_tui/src/dlog_tui_tests/test_utils.hpp +++ b/libs/deeplog_tui/src/dlog_tui_tests/test_utils.hpp @@ -10,7 +10,6 @@ #include #include -#include #include #include