From c7f0e9c3aaa8c6164e2fa235bce8081e61a7b5c6 Mon Sep 17 00:00:00 2001 From: DavidAce Date: Wed, 14 Feb 2024 09:19:08 +0100 Subject: [PATCH] Fix h5pp::format and h5pp::print for fmt versions < 8 --- examples/example-02c-stdvector-complex.cpp | 2 +- include/h5pp/details/h5ppFormat.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/examples/example-02c-stdvector-complex.cpp b/examples/example-02c-stdvector-complex.cpp index 17aaa90..564f693 100644 --- a/examples/example-02c-stdvector-complex.cpp +++ b/examples/example-02c-stdvector-complex.cpp @@ -1,7 +1,7 @@ #include template -void print_complex(fmt::format_string msg, const std::vector> &v) { +void print_complex(std::string_view msg, const std::vector> &v) { h5pp::print(msg); for(const auto &c : v) h5pp::print("{} + i{}, ", std::real(c), std::imag(c)); h5pp::print("\n"); diff --git a/include/h5pp/details/h5ppFormat.h b/include/h5pp/details/h5ppFormat.h index f11ff13..26ed5c5 100644 --- a/include/h5pp/details/h5ppFormat.h +++ b/include/h5pp/details/h5ppFormat.h @@ -46,6 +46,7 @@ #if defined(FMT_FORMAT_H_) && (defined(H5PP_USE_FMT) || defined(H5PP_USE_SPDLOG)) namespace h5pp { + #if defined(FMT_VERSION) && FMT_VERSION >= 80000 template [[nodiscard]] std::string format(fmt::format_string fs, Args &&...args) { return fmt::format(fs, std::forward(args)...); @@ -54,6 +55,16 @@ namespace h5pp { void print(fmt::format_string fs, Args &&...args) { fmt::print(fs, std::forward(args)...); } + #else + template + [[nodiscard]] std::string format(Args... args) { + return fmt::format(std::forward(args)...); + } + template + void print(Args... args) { + fmt::print(std::forward(args)...); + } + #endif } #else