From a63a85712f4cca2aa4ddd16b1e059a2f0f70b128 Mon Sep 17 00:00:00 2001 From: "M. Galib Uludag" Date: Wed, 29 Mar 2023 19:18:25 +0200 Subject: [PATCH] added std source_location support --- include/spdlog/details/source_location.h | 42 +++++++++++++++--------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/include/spdlog/details/source_location.h b/include/spdlog/details/source_location.h index 164db3a9..d2390f8d 100644 --- a/include/spdlog/details/source_location.h +++ b/include/spdlog/details/source_location.h @@ -4,6 +4,18 @@ #include +#ifdef __has_include +# if __has_include() && __cplusplus >= 202002L +# include +# define SPDLOG_SOURCE_LOCATION +# endif +#endif + +#ifdef SPDLOG_SOURCE_LOCATION +namespace spdlog::details { + using source_location = std::source_location; +} +#else namespace spdlog { namespace details { struct source_location { @@ -12,28 +24,28 @@ public: (__clang_major__ >= 9) static constexpr source_location current(const char *fileName = __builtin_FILE(), - const int lineNumber = __builtin_LINE(), + const unsigned lineNumber = __builtin_LINE(), const char *functionName = __builtin_FUNCTION(), - const int columnOffset = __builtin_COLUMN()) noexcept + const unsigned columnOffset = __builtin_COLUMN()) noexcept #elif defined(__GNUC__) && \ (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)) static constexpr source_location current(const char *fileName = __builtin_FILE(), - const int lineNumber = __builtin_LINE(), + const unsigned lineNumber = __builtin_LINE(), const char *functionName = __builtin_FUNCTION(), - const int columnOffset = 0) noexcept + const unsigned columnOffset = 0) noexcept #elif defined(_MSC_VER) && (_MSC_VER > 1925) static constexpr source_location current(const char *fileName = __builtin_FILE(), - const int lineNumber = __builtin_LINE(), + const unsigned lineNumber = __builtin_LINE(), const char *functionName = __builtin_FUNCTION(), - const int columnOffset = __builtin_COLUMN()) noexcept + const unsigned columnOffset = __builtin_COLUMN()) noexcept #else static constexpr source_location current(const char *fileName = "unsupported", - const int lineNumber = 0, + const unsigned lineNumber = 0, const char *functionName = "unsupported", - const int columnOffset = 0) noexcept + const unsigned columnOffset = 0) noexcept #endif { return source_location(fileName, lineNumber, functionName, columnOffset); @@ -46,23 +58,23 @@ public: constexpr const char *function_name() const noexcept { return functionName; } - constexpr int line() const noexcept { return lineNumber; } + constexpr unsigned line() const noexcept { return lineNumber; } - constexpr int column() const noexcept { return columnOffset; } + constexpr unsigned column() const noexcept { return columnOffset; } private: constexpr source_location(const char *fileName, - const int lineNumber, + const unsigned lineNumber, const char *functionName, - const int columnOffset) noexcept + const unsigned columnOffset) noexcept : fileName(fileName), lineNumber(lineNumber), functionName(functionName), columnOffset(columnOffset) {} const char *fileName; - const int lineNumber; + const unsigned lineNumber; const char *functionName; - const int columnOffset; + const unsigned columnOffset; }; } // namespace details - +#endif } // namespace spdlog