From bcf7848b81ccc33a9a0ba1bb63e37021ebaa5122 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Thu, 26 Sep 2024 01:12:05 +0200 Subject: [PATCH 1/3] [test] fix compile error on macOS Signed-off-by: Christian Parpart --- test-boxed-cpp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-boxed-cpp.cpp b/test-boxed-cpp.cpp index dcf107a..c5fa0fc 100644 --- a/test-boxed-cpp.cpp +++ b/test-boxed-cpp.cpp @@ -189,7 +189,7 @@ struct Wrap { overload func_wrap; - Wrap(Ts... funcs): func_wrap(funcs...) {} + Wrap(Ts... funcs): func_wrap { funcs... } {} template auto operator()(Args... args) From eff3f409ca045c6eaba6f689aa71a7465cd55ff6 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Thu, 26 Sep 2024 01:11:42 +0200 Subject: [PATCH 2/3] Add Ubuntu 24.04 to CI Signed-off-by: Christian Parpart --- .github/workflows/build.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9ff6374..d04857c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,7 +35,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-22.04, ubuntu-20.04] + os: [ubuntu-24.04, ubuntu-22.04, ubuntu-20.04] cxx: [20] build_type: ["RelWithDebInfo"] llvm_version: @@ -56,8 +56,6 @@ jobs: # max-size: 256M - name: "update APT database" run: sudo apt -q update - - - name: Install clang run: | wget https://apt.llvm.org/llvm.sh @@ -78,6 +76,5 @@ jobs: -DCMAKE_BUILD_TYPE=${{matrix.build_type}} - name: "build" run: cmake --build build --parallel 3 - - name: "run test" run: ./build/test-boxed-cpp From a6d1684a5c9d729e8f4021c7ff77f9a8400e7367 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Sun, 22 Sep 2024 11:09:32 +0200 Subject: [PATCH 3/3] Add support for C++20 format API Signed-off-by: Christian Parpart --- .github/workflows/build.yml | 2 +- include/boxed-cpp/boxed.hpp | 21 ++++++++++++++++----- test-boxed-cpp.cpp | 21 +++++++++++++++++++++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d04857c..b02eec7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,7 +35,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-24.04, ubuntu-22.04, ubuntu-20.04] + os: [ubuntu-24.04, ubuntu-22.04] cxx: [20] build_type: ["RelWithDebInfo"] llvm_version: diff --git a/include/boxed-cpp/boxed.hpp b/include/boxed-cpp/boxed.hpp index dfc7e46..5577971 100644 --- a/include/boxed-cpp/boxed.hpp +++ b/include/boxed-cpp/boxed.hpp @@ -207,19 +207,30 @@ struct hash> } // namespace std // {{{ fmtlib integration // clang-format off -#if __has_include() +#if __has_include() +#include +// clang-format on +template +struct std::formatter>: std::formatter +{ + auto format(boxed::detail::boxed const& val, auto& ctx) const + { + return std::formatter::format(val.value, ctx); + } +}; +#elif __has_include() + +// clang-format off #include // clang-format on template -struct fmt::formatter> +struct fmt::formatter>: fmt::formatter { - constexpr auto parse(fmt::format_parse_context& ctx) { return ctx.begin(); } - auto format(boxed::detail::boxed const& val, fmt::format_context& ctx) const { - return fmt::format_to(ctx.out(), "{}", val.value); + return fmt::formatter::format(val.value, ctx); } }; diff --git a/test-boxed-cpp.cpp b/test-boxed-cpp.cpp index c5fa0fc..7550fd1 100644 --- a/test-boxed-cpp.cpp +++ b/test-boxed-cpp.cpp @@ -215,3 +215,24 @@ TEST_CASE("advanced") REQUIRE(x_coord(rho, theta, phi) == x_coord(theta, phi, rho)); REQUIRE(x_coord(phi, theta, rho) == x_coord(phi, theta, rho)); } + +#ifdef __has_include + #if __has_include() + #include + #endif +#endif + +#if defined(__cpp_lib_format) // && __cpp_lib_format >= 202207LL +TEST_CASE("formatter") +{ + auto constexpr l = Length { 3 }; + auto constexpr f = From { 2 }; + auto constexpr t = To { 4 }; + auto constexpr bd = BoxedDouble { 3.14 }; + + REQUIRE(std::format("{}", l) == "3"); + REQUIRE(std::format("{}", f) == "2"); + REQUIRE(std::format("{}", t) == "4"); + REQUIRE(std::format("{}", bd) == "3.14"); +} +#endif