From 6e33fa13808248b9263f6f6c30dadc9e8fb5adff Mon Sep 17 00:00:00 2001 From: Stephan Lachnit Date: Mon, 8 Jan 2024 22:54:48 +0100 Subject: [PATCH 1/2] Always include if available Signed-off-by: Stephan Lachnit --- include/spdlog/common.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 1269c14af4..f6fb0fe74c 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -16,8 +16,13 @@ #include #include +#ifdef __has_include + #if __has_include() + #include + #endif +#endif + #ifdef SPDLOG_USE_STD_FORMAT - #include #if __cpp_lib_format >= 202207L #include #else From 916e54294ac3ad3a0fdbe4ab5e9c6be97370e81c Mon Sep 17 00:00:00 2001 From: Stephan Lachnit Date: Sat, 13 Jan 2024 11:18:42 +0100 Subject: [PATCH 2/2] Add constructor to spdlog::source_loc using std::source_location Signed-off-by: Stephan Lachnit --- include/spdlog/common.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/spdlog/common.h b/include/spdlog/common.h index f6fb0fe74c..77a73b8675 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -105,6 +105,12 @@ #endif #endif +// Add constructor to spdlog::source_loc using std::source_location +#if __cpp_lib_source_location >= 201907L + #define SPDLOG_STD_SOURCE_LOCATION + #include +#endif + #ifndef SPDLOG_FUNCTION #define SPDLOG_FUNCTION static_cast(__FUNCTION__) #endif @@ -324,6 +330,13 @@ struct source_loc { line{line_in}, funcname{funcname_in} {} + #ifdef SPDLOG_STD_SOURCE_LOCATION + SPDLOG_CONSTEXPR source_loc(const std::source_location& loc) + : filename{loc.file_name()}, + line{static_cast(loc.line())}, + funcname{loc.function_name()} {} + #endif + SPDLOG_CONSTEXPR bool empty() const SPDLOG_NOEXCEPT { return line == 0; } const char *filename{nullptr}; int line{0};