diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d86f6c24..2f41355cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -194,7 +194,7 @@ include(FetchContent) FetchContent_Declare( fmt GIT_REPOSITORY https://github.com/fmtlib/fmt.git - GIT_TAG 10.2.1 + GIT_TAG 11.0.2 ) FetchContent_Declare( diff --git a/blocks/soapy/include/gnuradio-4.0/soapy/SoapyRaiiWrapper.hpp b/blocks/soapy/include/gnuradio-4.0/soapy/SoapyRaiiWrapper.hpp index bf7cdd217..bb4a44185 100644 --- a/blocks/soapy/include/gnuradio-4.0/soapy/SoapyRaiiWrapper.hpp +++ b/blocks/soapy/include/gnuradio-4.0/soapy/SoapyRaiiWrapper.hpp @@ -780,7 +780,7 @@ static_assert(std::is_default_constructible_v struct fmt::formatter { - constexpr auto parse(format_parse_context& ctx) const noexcept { return ctx.begin(); } + constexpr auto parse(fmt::format_parse_context& ctx) const noexcept { return ctx.begin(); } template auto format(const gr::blocks::soapy::Range& range, FormatContext& ctx) const noexcept { diff --git a/core/include/gnuradio-4.0/BlockModel.hpp b/core/include/gnuradio-4.0/BlockModel.hpp index 6614858af..c4aebc6b3 100644 --- a/core/include/gnuradio-4.0/BlockModel.hpp +++ b/core/include/gnuradio-4.0/BlockModel.hpp @@ -525,7 +525,7 @@ struct fmt::formatter { } template - auto format(const gr::Edge& e, FormatContext& ctx) { + auto format(const gr::Edge& e, FormatContext& ctx) const { const auto& name = [this](const gr::BlockModel* block) { return (formatSpecifier == 'l') ? block->uniqueName() : block->name(); }; const auto portIndex = [](const gr::PortDefinition& port) { diff --git a/core/include/gnuradio-4.0/Sequence.hpp b/core/include/gnuradio-4.0/Sequence.hpp index 164edcb9f..36f8b2678 100644 --- a/core/include/gnuradio-4.0/Sequence.hpp +++ b/core/include/gnuradio-4.0/Sequence.hpp @@ -177,7 +177,7 @@ struct fmt::formatter { } template - auto format(gr::Sequence const& value, FormatContext& ctx) { + auto format(gr::Sequence const& value, FormatContext& ctx) const { return fmt::format_to(ctx.out(), "{}", value.value()); } }; diff --git a/core/include/gnuradio-4.0/annotated.hpp b/core/include/gnuradio-4.0/annotated.hpp index ae5d849fb..ed76395b3 100644 --- a/core/include/gnuradio-4.0/annotated.hpp +++ b/core/include/gnuradio-4.0/annotated.hpp @@ -423,7 +423,7 @@ struct fmt::formatter> { } template - constexpr auto format(const gr::Annotated& annotated, FormatContext& ctx) { + constexpr auto format(const gr::Annotated& annotated, FormatContext& ctx) const { // TODO: add switch for printing only brief and/or meta-information return value_formatter.format(annotated.value, ctx); } diff --git a/core/include/gnuradio-4.0/thread/thread_affinity.hpp b/core/include/gnuradio-4.0/thread/thread_affinity.hpp index 9273f162a..43c13aa16 100644 --- a/core/include/gnuradio-4.0/thread/thread_affinity.hpp +++ b/core/include/gnuradio-4.0/thread/thread_affinity.hpp @@ -258,7 +258,7 @@ struct fmt::formatter { } template - auto format(Policy policy, FormatContext& ctx) { + auto format(Policy policy, FormatContext& ctx) const { std::string policy_name; switch (policy) { case Policy::UNKNOWN: policy_name = "UNKNOWN"; break; diff --git a/meta/include/gnuradio-4.0/meta/formatter.hpp b/meta/include/gnuradio-4.0/meta/formatter.hpp index 82964bb37..cac9ded16 100644 --- a/meta/include/gnuradio-4.0/meta/formatter.hpp +++ b/meta/include/gnuradio-4.0/meta/formatter.hpp @@ -2,8 +2,6 @@ #define GNURADIO_FORMATTER_HPP #include -#include -#include #include #include #include @@ -23,66 +21,10 @@ namespace time { } // namespace time } // namespace gr -template -struct fmt::formatter> { - char presentation = 'g'; // default format - - template - constexpr auto parse(ParseContext& ctx) { - auto it = ctx.begin(), end = ctx.end(); - if (it != end && (*it == 'f' || *it == 'F' || *it == 'e' || *it == 'E' || *it == 'g' || *it == 'G')) { - presentation = *it++; - } - if (it != end && *it != '}') { - throw fmt::format_error("invalid format"); - } - return it; - } - - template - constexpr auto format(const std::complex& value, FormatContext& ctx) const { - // format according to: https://fmt.dev/papers/p2197r0.html#examples - const auto imag = value.imag(); - switch (presentation) { - case 'e': - if (imag == 0) { - return fmt::format_to(ctx.out(), "{:e}", value.real()); - } - return fmt::format_to(ctx.out(), "({:e}{:+e}i)", value.real(), imag); - case 'E': - if (imag == 0) { - return fmt::format_to(ctx.out(), "{:E}", value.real()); - } - return fmt::format_to(ctx.out(), "({:E}{:+E}i)", value.real(), imag); - case 'f': - if (imag == 0) { - return fmt::format_to(ctx.out(), "{:f}", value.real()); - } - return fmt::format_to(ctx.out(), "({:f}{:+f}i)", value.real(), imag); - case 'F': - if (imag == 0) { - return fmt::format_to(ctx.out(), "{:F}", value.real()); - } - return fmt::format_to(ctx.out(), "({:F}{:+F}i)", value.real(), imag); - case 'G': - if (imag == 0) { - return fmt::format_to(ctx.out(), "{:G}", value.real()); - } - return fmt::format_to(ctx.out(), "({:G}{:+G}i)", value.real(), imag); - case 'g': - default: - if (imag == 0) { - return fmt::format_to(ctx.out(), "{:g}", value.real()); - } - return fmt::format_to(ctx.out(), "({:g}{:+g}i)", value.real(), imag); - } - } -}; - // simplified formatter for UncertainValue template struct fmt::formatter> { - constexpr auto parse(format_parse_context& ctx) const noexcept -> decltype(ctx.begin()) { return ctx.begin(); } + constexpr auto parse(fmt::format_parse_context& ctx) const noexcept -> decltype(ctx.begin()) { return ctx.begin(); } template constexpr auto format(const gr::UncertainValue& value, FormatContext& ctx) const noexcept { @@ -126,7 +68,7 @@ constexpr std::string join(const Container& container, const Separator& separato template<> struct fmt::formatter { - constexpr auto parse(format_parse_context& ctx) const noexcept -> decltype(ctx.begin()) { return ctx.begin(); } + constexpr auto parse(fmt::format_parse_context& ctx) const noexcept -> decltype(ctx.begin()) { return ctx.begin(); } template auto format(const pmtv::map_t::value_type& kv, FormatContext& ctx) const noexcept { @@ -136,7 +78,7 @@ struct fmt::formatter { template struct fmt::formatter { // alternate pmtv formatter optimised for compile-time not runtime - constexpr auto parse(format_parse_context& ctx) const noexcept -> decltype(ctx.begin()) { return ctx.begin(); } + constexpr auto parse(fmt::format_parse_context& ctx) const noexcept -> decltype(ctx.begin()) { return ctx.begin(); } template auto format(const T& value, FormatContext& ctx) const noexcept { @@ -180,7 +122,7 @@ struct fmt::formatter { // alternate pmtv formatter optimised for compile-tim template<> struct fmt::formatter { - constexpr auto parse(format_parse_context& ctx) const noexcept -> decltype(ctx.begin()) { return ctx.begin(); } + constexpr auto parse(fmt::format_parse_context& ctx) const noexcept -> decltype(ctx.begin()) { return ctx.begin(); } template constexpr auto format(const pmtv::map_t& value, FormatContext& ctx) const noexcept { @@ -194,7 +136,7 @@ template<> struct fmt::formatter> { char presentation = 'c'; - constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) { + constexpr auto parse(fmt::format_parse_context& ctx) -> decltype(ctx.begin()) { auto it = ctx.begin(), end = ctx.end(); if (it != end && (*it == 's' || *it == 'c')) { presentation = *it++; @@ -221,18 +163,4 @@ struct fmt::formatter> { } }; -template -struct fmt::formatter> { - constexpr auto parse(format_parse_context& ctx) const noexcept -> decltype(ctx.begin()) { return ctx.begin(); } - - template - auto format(const std::expected& ret, FormatContext& ctx) const -> decltype(ctx.out()) { - if (ret.has_value()) { - return fmt::format_to(ctx.out(), "", ret.value()); - } else { - return fmt::format_to(ctx.out(), "", ret.error()); - } - } -}; - #endif // GNURADIO_FORMATTER_HPP diff --git a/meta/test/qa_formatter.cpp b/meta/test/qa_formatter.cpp index 636bc1c4e..8d632fb62 100644 --- a/meta/test/qa_formatter.cpp +++ b/meta/test/qa_formatter.cpp @@ -1,71 +1,11 @@ #include -#include -#include - #include #include namespace gr::meta::test { -const boost::ut::suite complexFormatter = [] { - using namespace boost::ut; - using namespace std::literals::complex_literals; - using namespace std::literals::string_literals; - - using C = std::complex; - "fmt::formatter>"_test = [] { - expect(eq("(1+1i)"s, fmt::format("{}", C(1., +1.)))); - expect(eq("(1-1i)"s, fmt::format("{}", C(1., -1.)))); - expect(eq("1"s, fmt::format("{}", C(1., 0.)))); - expect(eq("(1.234+1.12346e+12i)"s, fmt::format("{}", C(1.234, 1123456789012)))); - expect(eq("(1+1i)"s, fmt::format("{:g}", C(1., +1.)))); - expect(eq("(1-1i)"s, fmt::format("{:g}", C(1., -1.)))); - expect(eq("1"s, fmt::format("{:g}", C(1., 0.)))); - expect(eq("(1.12346e+12+1.234i)"s, fmt::format("{:g}", C(1123456789012, 1.234)))); - expect(eq("1.12346e+12"s, fmt::format("{:g}", C(1123456789012, 0)))); - expect(eq("(1.234+1.12346e+12i)"s, fmt::format("{:g}", C(1.234, 1123456789012)))); - expect(eq("(1.12346E+12+1.234i)"s, fmt::format("{:G}", C(1123456789012, 1.234)))); - expect(eq("1.12346E+12"s, fmt::format("{:G}", C(1123456789012, 0)))); - expect(eq("(1.234+1.12346E+12i)"s, fmt::format("{:G}", C(1.234, 1123456789012)))); - - expect(eq("(1.000000+1.000000i)"s, fmt::format("{:f}", C(1., +1.)))); - expect(eq("(1.000000-1.000000i)"s, fmt::format("{:f}", C(1., -1.)))); - expect(eq("1.000000"s, fmt::format("{:f}", C(1., 0.)))); - expect(eq("(1.000000+1.000000i)"s, fmt::format("{:F}", C(1., +1.)))); - expect(eq("(1.000000-1.000000i)"s, fmt::format("{:F}", C(1., -1.)))); - expect(eq("1.000000"s, fmt::format("{:F}", C(1., 0.)))); - - expect(eq("(1.000000e+00+1.000000e+00i)"s, fmt::format("{:e}", C(1., +1.)))); - expect(eq("(1.000000e+00-1.000000e+00i)"s, fmt::format("{:e}", C(1., -1.)))); - expect(eq("1.000000e+00"s, fmt::format("{:e}", C(1., 0.)))); - expect(eq("(1.000000E+00+1.000000E+00i)"s, fmt::format("{:E}", C(1., +1.)))); - expect(eq("(1.000000E+00-1.000000E+00i)"s, fmt::format("{:E}", C(1., -1.)))); - expect(eq("1.000000E+00"s, fmt::format("{:E}", C(1., 0.)))); - }; -}; - -const boost::ut::suite uncertainValueFormatter = [] { - using namespace boost::ut; - using namespace std::literals::complex_literals; - using namespace std::literals::string_literals; - using UncertainDouble = gr::UncertainValue; - using UncertainComplex = gr::UncertainValue>; - - "fmt::formatter>"_test = [] { - // Test with UncertainValue - expect(eq("(1.23 ± 0.45)"s, fmt::format("{}", UncertainDouble{1.23, 0.45}))); - expect(eq("(3.14 ± 0.01)"s, fmt::format("{}", UncertainDouble{3.14, 0.01}))); - expect(eq("(0 ± 0)"s, fmt::format("{}", UncertainDouble{0, 0}))); - - // Test with UncertainValue> - expect(eq("((1+2i) ± (0.1+0.2i))"s, fmt::format("{}", UncertainComplex{{1, 2}, {0.1, 0.2}}))); - expect(eq("((3.14+1.59i) ± (0.01+0.02i))"s, fmt::format("{}", UncertainComplex{{3.14, 1.59}, {0.01, 0.02}}))); - expect(eq("(0 ± 0)"s, fmt::format("{}", UncertainComplex{{0, 0}, {0, 0}}))); - }; -}; - const boost::ut::suite propertyMapFormatter = [] { using namespace boost::ut; using namespace std::literals::string_literals; @@ -91,20 +31,6 @@ const boost::ut::suite vectorBoolFormatter = [] { }; }; -const boost::ut::suite expectedFormatter = [] { - using namespace boost::ut; - using namespace std::string_literals; - using Expected = std::expected; - - auto value = fmt::format("{}", Expected(5)); - fmt::println("expected formatter test: {}", value); - expect(eq(value, ""s)); - - auto error = fmt::format("{}", Expected(std::unexpected("Error"))); - fmt::println("expected formatter test: {}", error); - expect(eq(error, ""s)); -}; - } // namespace gr::meta::test int main() { /* tests are statically executed */ } \ No newline at end of file