Skip to content

Commit

Permalink
Fix h5pp::format and h5pp::print for fmt versions < 8
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAce committed Feb 14, 2024
1 parent fca5b41 commit c7f0e9c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/example-02c-stdvector-complex.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <h5pp/h5pp.h>

template<typename ...Args>
void print_complex(fmt::format_string<Args...> msg, const std::vector<std::complex<double>> &v) {
void print_complex(std::string_view msg, const std::vector<std::complex<double>> &v) {
h5pp::print(msg);
for(const auto &c : v) h5pp::print("{} + i{}, ", std::real(c), std::imag(c));
h5pp::print("\n");
Expand Down
11 changes: 11 additions & 0 deletions include/h5pp/details/h5ppFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename... Args>
[[nodiscard]] std::string format(fmt::format_string<Args...> fs, Args &&...args) {
return fmt::format(fs, std::forward<Args>(args)...);
Expand All @@ -54,6 +55,16 @@ namespace h5pp {
void print(fmt::format_string<Args...> fs, Args &&...args) {
fmt::print(fs, std::forward<Args>(args)...);
}
#else
template<typename... Args>
[[nodiscard]] std::string format(Args... args) {
return fmt::format(std::forward<Args>(args)...);
}
template<typename... Args>
void print(Args... args) {
fmt::print(std::forward<Args>(args)...);
}
#endif
}
#else

Expand Down

0 comments on commit c7f0e9c

Please sign in to comment.