From 3979bd15f784c80e96ecb9f0c126670fddbfea75 Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 16 Sep 2023 17:23:04 +0300 Subject: [PATCH] Fixed build --- include/spdlog/common.h | 12 ++++++++++-- include/spdlog/logger.h | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 7c87ff08..2bd4e5d8 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -339,18 +339,26 @@ constexpr spdlog::wstring_view_t to_string_view(spdlog::wstring_view_t str) noex } #endif +// convert format_string<...> to string_view depending on std::format or {fmt} versions #ifndef SPDLOG_USE_STD_FORMAT template -inline fmt::basic_string_view to_string_view(fmt::basic_format_string fmt) +constexpr inline fmt::basic_string_view to_string_view(fmt::basic_format_string fmt) noexcept { return fmt; } -#elif __cpp_lib_format >= 202207L +#elif __cpp_lib_format >= 202207L // std::format and __cpp_lib_format >= 202207L template constexpr std::basic_string_view to_string_view(std::basic_format_string fmt) noexcept { return fmt.get(); } +#else // std::format and __cpp_lib_format < 202207L +template +constexpr std::basic_string_view to_string_view(std::basic_format_string fmt) noexcept +{ + return fmt; +} + #endif } // namespace details diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 14a8069a..ec4cd029 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -81,7 +81,7 @@ public: { if (should_log(lvl)) { - log_with_format_(loc, lvl, fmt.get(), std::forward(args)...); + log_with_format_(loc, lvl, details::to_string_view(fmt), std::forward(args)...); } } @@ -90,7 +90,7 @@ public: { if (should_log(lvl)) { - log_with_format_(source_loc{}, lvl, fmt.get(), std::forward(args)...); + log_with_format_(source_loc{}, lvl, details::to_string_view(fmt), std::forward(args)...); } }