header_utils
Loading...
Searching...
No Matches
source_location.h
1
4
5#pragma once
6
7#include <cstdint>
8
9#if defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L && !defined(DOXYGEN)
10#include <source_location>
11namespace ghassanpl
12{
13 using std::source_location;
14}
15#elif defined(__cpp_consteval)
16namespace ghassanpl
17{
18 struct source_location
19 {
20 [[nodiscard]] static consteval source_location current(const uint_least32_t _Line_ = __builtin_LINE(),
21 const uint_least32_t _Column_ = __builtin_COLUMN(), const char* const _File_ = __builtin_FILE(),
22#if defined(__clang__) || defined(__EDG__) // TRANSITION, DevCom-10199227 and LLVM-58951
23 const char* const _Function_ = __builtin_FUNCTION()
24#else // ^^^ workaround / no workaround vvv
25 const char* const _Function_ = __builtin_FUNCSIG()
26#endif // TRANSITION, DevCom-10199227 and LLVM-58951
27 ) noexcept {
28 source_location _Result{};
29 _Result._Line = _Line_;
30 _Result._Column = _Column_;
31 _Result._File = _File_;
32 _Result._Function = _Function_;
33 return _Result;
34 }
35
36 [[nodiscard]] constexpr source_location() noexcept = default;
37
38 [[nodiscard]] constexpr uint_least32_t line() const noexcept {
39 return _Line;
40 }
41 [[nodiscard]] constexpr uint_least32_t column() const noexcept {
42 return _Column;
43 }
44 [[nodiscard]] constexpr const char* file_name() const noexcept {
45 return _File;
46 }
47 [[nodiscard]] constexpr const char* function_name() const noexcept {
48 return _Function;
49 }
50
51 private:
52 uint_least32_t _Line{};
53 uint_least32_t _Column{};
54 const char* _File = "";
55 const char* _Function = "";
56 };
57}
58#else
59#error "source_location is not supported"
60#endif
61
62namespace ghassanpl
63{
64 template <typename STRINGIFIER>
65 auto stringify(STRINGIFIER& str, const source_location& b) { return str(b.file_name(), '(', b.line(), ", ", b.column(), "):"); }
66}
Primary namespace for everything in this library.
Definition align+rec2.h:10