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;