Skip to content

Commit

Permalink
Add constructor to spdlog::source_loc using std::source_location
Browse files Browse the repository at this point in the history
Signed-off-by: Stephan Lachnit <[email protected]>
  • Loading branch information
stephanlachnit committed Jan 13, 2024
1 parent 6e33fa1 commit 916e542
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions include/spdlog/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <source_location>
#endif

#ifndef SPDLOG_FUNCTION
#define SPDLOG_FUNCTION static_cast<const char *>(__FUNCTION__)
#endif
Expand Down Expand Up @@ -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<int>(loc.line())},
funcname{loc.function_name()} {}
#endif

SPDLOG_CONSTEXPR bool empty() const SPDLOG_NOEXCEPT { return line == 0; }
const char *filename{nullptr};
int line{0};
Expand Down

0 comments on commit 916e542

Please sign in to comment.