From 8740857a47a8f61d5ca861e1c16140bf4b5f70f9 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Thu, 16 Sep 2021 20:24:27 +0200 Subject: [PATCH] build: fmt updated to 8.0.1 --- conanfile.py | 2 +- docs/CHANGELOG.md | 1 + example/glide_computer/include/geographic.h | 6 +++--- example/kalman_filter/kalman.h | 6 ++++-- src/core-fmt/include/units/format.h | 7 +++---- test/unit_test/runtime/fmt_test.cpp | 4 ++-- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/conanfile.py b/conanfile.py index 0892dd3b..8ee6e8e5 100644 --- a/conanfile.py +++ b/conanfile.py @@ -37,7 +37,7 @@ class UnitsConan(ConanFile): url = "https://github.com/mpusz/units" settings = "os", "compiler", "build_type", "arch" requires = ( - "fmt/7.1.3", + "fmt/8.0.1", "gsl-lite/0.38.1" ) options = { diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 809e0326..9610f43a 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -7,6 +7,7 @@ - (!) fix: add `quantity_point::origin`, like `std::chrono::time_point::clock` - fix: account for different dimensions in `quantity_point_cast`'s constraint - build: Minimum Conan version changed to 1.40 + - build: fmt updated to 8.0.1 - build: gsl-lite updated to 0.38.1 - build: catch2 updated to 2.13.7 - build: doxygen updated to 1.9.2 diff --git a/example/glide_computer/include/geographic.h b/example/glide_computer/include/geographic.h index 041c046f..fd2ca4db 100644 --- a/example/glide_computer/include/geographic.h +++ b/example/glide_computer/include/geographic.h @@ -44,7 +44,7 @@ template struct coordinate { using value_type = Rep; constexpr explicit coordinate(value_type v) : value_(v) {} - value_type value() const { return value_; } + constexpr value_type value() const { return value_; } auto operator<=>(const coordinate&) const = default; private: value_type value_; @@ -110,7 +110,7 @@ struct fmt::formatter : formatter auto format(geographic::latitude lat, FormatContext& ctx) { - format_to(ctx.out(), lat.value() > 0 ? "N" : "S"); + format_to(ctx.out(), fmt::runtime(lat.value() > 0 ? "N" : "S")); return formatter::format(lat.value() > 0 ? lat.value() : -lat.value(), ctx); } }; @@ -120,7 +120,7 @@ struct fmt::formatter : formatter auto format(geographic::longitude lon, FormatContext& ctx) { - format_to(ctx.out(), lon.value() > 0 ? "E" : "W"); + format_to(ctx.out(), fmt::runtime(lon.value() > 0 ? "E" : "W")); return formatter::format(lon.value() > 0 ? lon.value() : -lon.value(), ctx); } }; diff --git a/example/kalman_filter/kalman.h b/example/kalman_filter/kalman.h index f78cc289..000153b0 100644 --- a/example/kalman_filter/kalman.h +++ b/example/kalman_filter/kalman.h @@ -184,7 +184,8 @@ struct fmt::formatter> { units::detail::global_format_specs global_specs = { specs.fill, specs.align, specs.width }; units::detail::format_global_buffer(std::back_inserter(global_format_buffer), global_specs); - return format_to(ctx.out(), to_string(global_format_buffer), to_string(value_buffer)); + return format_to(ctx.out(), fmt::runtime(std::string_view(global_format_buffer.data(), global_format_buffer.size())), + std::string_view(value_buffer.data(), value_buffer.size())); } private: detail::dynamic_format_specs specs; @@ -221,7 +222,8 @@ struct fmt::formatter> { units::detail::global_format_specs global_specs = { specs.fill, specs.align, specs.width }; units::detail::format_global_buffer(std::back_inserter(global_format_buffer), global_specs); - return format_to(ctx.out(), to_string(global_format_buffer), to_string(value_buffer)); + return format_to(ctx.out(), fmt::runtime(std::string_view(global_format_buffer.data(), global_format_buffer.size())), + std::string_view(value_buffer.data(), value_buffer.size())); } private: detail::dynamic_format_specs specs; diff --git a/src/core-fmt/include/units/format.h b/src/core-fmt/include/units/format.h index ff3b3894..14f28cb3 100644 --- a/src/core-fmt/include/units/format.h +++ b/src/core-fmt/include/units/format.h @@ -33,7 +33,6 @@ UNITS_DIAGNOSTIC_PUSH UNITS_DIAGNOSTIC_IGNORE_UNREACHABLE UNITS_DIAGNOSTIC_IGNORE_SHADOW #include -#include UNITS_DIAGNOSTIC_POP // IWYU pragma: end_exports @@ -251,9 +250,9 @@ namespace units { } fmt::format_to(to_buffer, "}}"); if (rep_specs.use_locale and static_cast(loc)) { - return format_to(out, loc.template get(), fmt::to_string(buffer), val); + return format_to(out, loc.template get(), fmt::runtime(std::string_view(buffer.data(), buffer.size())), val); } - return format_to(out, fmt::to_string(buffer), val); + return format_to(out, fmt::runtime(std::string_view(buffer.data(), buffer.size())), val); } // Creates a global format string @@ -510,6 +509,6 @@ public: // Format the `quantity buffer` using specs from `global_format_buffer` // In the example, equivalent to fmt::format("{:*^10}", "1.2_m") - return format_to(ctx.out(), fmt::to_string(global_format_buffer), fmt::to_string(quantity_buffer)); + return format_to(ctx.out(), fmt::runtime(std::basic_string_view(global_format_buffer.data(), global_format_buffer.size())), std::string_view(quantity_buffer.data(), quantity_buffer.size())); } }; diff --git a/test/unit_test/runtime/fmt_test.cpp b/test/unit_test/runtime/fmt_test.cpp index 2ab232e4..89a34b1e 100644 --- a/test/unit_test/runtime/fmt_test.cpp +++ b/test/unit_test/runtime/fmt_test.cpp @@ -1034,12 +1034,12 @@ TEST_CASE("precision specification for integral representation should throw", "[ { SECTION("full format {:%Q %q} on a quantity") { - REQUIRE_THROWS_MATCHES(fmt::format("{:%.1Q %q}", 1_q_m), fmt::format_error, Message("precision not allowed for integral quantity representation")); + REQUIRE_THROWS_MATCHES(fmt::format(fmt::runtime("{:%.1Q %q}"), 1_q_m), fmt::format_error, Message("precision not allowed for integral quantity representation")); } SECTION("value only format {:%Q} on a quantity") { - REQUIRE_THROWS_MATCHES(fmt::format("{:%.1Q}", 1_q_m), fmt::format_error, Message("precision not allowed for integral quantity representation")); + REQUIRE_THROWS_MATCHES(fmt::format(fmt::runtime("{:%.1Q}"), 1_q_m), fmt::format_error, Message("precision not allowed for integral quantity representation")); } }