Last active
March 17, 2022 03:21
-
-
Save falsycat/0ad672ba2aafb226d72d96af2ff1ccd2 to your computer and use it in GitHub Desktop.
std::source_location implementation for Clang (MIT)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#if defined(__clang__) | |
#include <cstdint> | |
namespace std { | |
// source_location impl for Clang | |
// reference: | |
// https://github.com/paweldac/source_location/blob/ff0002f92cdde3576ce02048dd9eb7823cabdc7b/include/source_location/source_location.hpp | |
struct source_location { | |
public: | |
static constexpr source_location current( | |
const char* file = __builtin_FILE(), | |
const char* func = __builtin_FUNCTION(), | |
uint_least32_t line = __builtin_LINE(), | |
uint_least32_t col = __builtin_COLUMN()) noexcept { | |
return source_location(file, func, line, col); | |
} | |
source_location(const source_location&) = default; | |
source_location(source_location&&) = default; | |
source_location& operator=(const source_location&) = default; | |
source_location& operator=(source_location&&) = default; | |
constexpr const char* file_name() const noexcept { return file_; } | |
constexpr const char* function_name() const noexcept { return func_; } | |
constexpr uint_least32_t line() const noexcept { return line_; } | |
constexpr std::uint_least32_t column() const noexcept { return col_; } | |
private: | |
constexpr source_location( | |
const char* file, const char* func, uint_least32_t line, uint_least32_t col) noexcept : | |
file_(file), func_(func), line_(line), col_(col) { | |
} | |
const char* file_; | |
const char* func_; | |
uint_least32_t line_; | |
uint_least32_t col_; | |
}; | |
} // namespace std | |
#else | |
# include <source_location> | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment