From 5632605d7717e9771ca03083242ce4899eec8ac1 Mon Sep 17 00:00:00 2001 From: Charles Milette Date: Fri, 4 Feb 2022 14:16:28 -0500 Subject: [PATCH] Support conversion from std::source_location to spdlog::source_loc Enabled better interop between spdlog and code using std::source_location --- include/spdlog/common.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 0d614dfc..305a9ed4 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -16,6 +16,17 @@ #include #include +#ifdef __has_include +#if __has_include() +#include +#endif +#endif + +#if __cpp_lib_source_location >= 201907L +#include +#define SPDLOG_HAS_STD_SOURCE_LOC +#endif + #ifdef SPDLOG_USE_STD_FORMAT # include #endif @@ -290,12 +301,18 @@ private: struct source_loc { SPDLOG_CONSTEXPR source_loc() = default; - SPDLOG_CONSTEXPR source_loc(const char *filename_in, int line_in, const char *funcname_in) + SPDLOG_CONSTEXPR source_loc(const char *filename_in, int line_in, const char *funcname_in) SPDLOG_NOEXCEPT : filename{filename_in} , line{line_in} , funcname{funcname_in} {} + SPDLOG_CONSTEXPR source_loc(std::source_location loc) SPDLOG_NOEXCEPT + : filename{loc.file_name()} + , line{static_cast(loc.line())} + , funcname{loc.function_name()} + {} + SPDLOG_CONSTEXPR bool empty() const SPDLOG_NOEXCEPT { return line == 0;