added std source_location support

pull/2690/head
M. Galib Uludag 2 years ago committed by GitHub
parent dc3e1e6bd1
commit a63a85712f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,6 +4,18 @@
#include <cstdint> #include <cstdint>
#ifdef __has_include
# if __has_include(<source_location>) && __cplusplus >= 202002L
# include <source_location>
# define SPDLOG_SOURCE_LOCATION
# endif
#endif
#ifdef SPDLOG_SOURCE_LOCATION
namespace spdlog::details {
using source_location = std::source_location;
}
#else
namespace spdlog { namespace spdlog {
namespace details { namespace details {
struct source_location { struct source_location {
@ -12,28 +24,28 @@ public:
(__clang_major__ >= 9) (__clang_major__ >= 9)
static constexpr source_location static constexpr source_location
current(const char *fileName = __builtin_FILE(), current(const char *fileName = __builtin_FILE(),
const int lineNumber = __builtin_LINE(), const unsigned lineNumber = __builtin_LINE(),
const char *functionName = __builtin_FUNCTION(), const char *functionName = __builtin_FUNCTION(),
const int columnOffset = __builtin_COLUMN()) noexcept const unsigned columnOffset = __builtin_COLUMN()) noexcept
#elif defined(__GNUC__) && \ #elif defined(__GNUC__) && \
(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)) (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
static constexpr source_location static constexpr source_location
current(const char *fileName = __builtin_FILE(), current(const char *fileName = __builtin_FILE(),
const int lineNumber = __builtin_LINE(), const unsigned lineNumber = __builtin_LINE(),
const char *functionName = __builtin_FUNCTION(), const char *functionName = __builtin_FUNCTION(),
const int columnOffset = 0) noexcept const unsigned columnOffset = 0) noexcept
#elif defined(_MSC_VER) && (_MSC_VER > 1925) #elif defined(_MSC_VER) && (_MSC_VER > 1925)
static constexpr source_location static constexpr source_location
current(const char *fileName = __builtin_FILE(), current(const char *fileName = __builtin_FILE(),
const int lineNumber = __builtin_LINE(), const unsigned lineNumber = __builtin_LINE(),
const char *functionName = __builtin_FUNCTION(), const char *functionName = __builtin_FUNCTION(),
const int columnOffset = __builtin_COLUMN()) noexcept const unsigned columnOffset = __builtin_COLUMN()) noexcept
#else #else
static constexpr source_location static constexpr source_location
current(const char *fileName = "unsupported", current(const char *fileName = "unsupported",
const int lineNumber = 0, const unsigned lineNumber = 0,
const char *functionName = "unsupported", const char *functionName = "unsupported",
const int columnOffset = 0) noexcept const unsigned columnOffset = 0) noexcept
#endif #endif
{ {
return source_location(fileName, lineNumber, functionName, columnOffset); return source_location(fileName, lineNumber, functionName, columnOffset);
@ -46,23 +58,23 @@ public:
constexpr const char *function_name() const noexcept { return functionName; } 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: private:
constexpr source_location(const char *fileName, constexpr source_location(const char *fileName,
const int lineNumber, const unsigned lineNumber,
const char *functionName, const char *functionName,
const int columnOffset) noexcept const unsigned columnOffset) noexcept
: fileName(fileName), lineNumber(lineNumber), functionName(functionName), : fileName(fileName), lineNumber(lineNumber), functionName(functionName),
columnOffset(columnOffset) {} columnOffset(columnOffset) {}
const char *fileName; const char *fileName;
const int lineNumber; const unsigned lineNumber;
const char *functionName; const char *functionName;
const int columnOffset; const unsigned columnOffset;
}; };
} // namespace details } // namespace details
#endif
} // namespace spdlog } // namespace spdlog

Loading…
Cancel
Save