3
3
4
4
#include < tempest/int.hpp>
5
5
6
- #include < source_location>
7
-
8
6
namespace tempest
9
7
{
10
8
struct source_location
11
9
{
12
10
public:
13
- #if defined(_MSC_VER)
14
- static consteval source_location current (const uint32_t line = __builtin_LINE(),
15
- const uint32_t column = __builtin_COLUMN(),
16
- const char* file = __builtin_FILE(),
17
- const char* func = __builtin_FUNCSIG()) noexcept ;
18
- #elif defined(__GNUC__)
19
- static consteval source_location current (const uint32_t line = __builtin_LINE(),
20
- const uint32_t column = __builtin_COLUMN(),
21
- const char* file = __builtin_FILE(),
22
- const char* func = __builtin_source_location()->_M_function_name) noexcept ;
23
- #else
24
- #error "Unsupported compiler."
25
- #endif
26
-
27
11
constexpr source_location () noexcept = default;
12
+ consteval source_location (const uint32_t line, const uint32_t column, const char * file, const char * func);
28
13
29
14
constexpr const char * file_name () const noexcept ;
30
15
constexpr const char * function_name () const noexcept ;
@@ -33,47 +18,51 @@ namespace tempest
33
18
constexpr size_t column () const noexcept ;
34
19
35
20
private:
36
- struct impl
37
- {
38
- const char * _file = nullptr ;
39
- const char * _function = nullptr ;
40
- uint32_t _line = 0 ;
41
- uint32_t _column = 0 ;
42
- };
43
-
44
- impl _impl;
21
+ const char * _file = nullptr ;
22
+ const char * _function = nullptr ;
23
+ uint32_t _line = 0 ;
24
+ uint32_t _column = 0 ;
45
25
};
46
26
47
- inline consteval source_location source_location::current (const uint32_t line, const uint32_t column,
48
- const char * file, const char * func) noexcept
27
+ inline consteval source_location::source_location (const uint32_t line, const uint32_t column, const char * file,
28
+ const char * func)
29
+ : _file{file}, _function{func}, _line{line}, _column{column}
49
30
{
50
- source_location loc;
51
- loc._impl ._file = file;
52
- loc._impl ._function = func;
53
- loc._impl ._line = line;
54
- loc._impl ._column = column;
55
- return loc;
56
31
}
57
32
58
33
inline constexpr const char * source_location::file_name () const noexcept
59
34
{
60
- return _impl. _file ;
35
+ return _file;
61
36
}
62
37
63
38
inline constexpr const char * source_location::function_name () const noexcept
64
39
{
65
- return _impl. _function ;
40
+ return _function;
66
41
}
67
42
68
43
inline constexpr size_t source_location::line () const noexcept
69
44
{
70
- return _impl. _line ;
45
+ return _line;
71
46
}
72
47
73
48
inline constexpr size_t source_location::column () const noexcept
74
49
{
75
- return _impl. _column ;
50
+ return _column;
76
51
}
77
52
} // namespace tempest
78
53
54
+ #if defined(_MSC_VER)
55
+
56
+ #define TEMPEST_CURRENT_SOURCE_LOCATION () \
57
+ ::tempest::source_location::source_location (__builtin_LINE(), __builtin_COLUMN(), __builtin_FILE(), \
58
+ __builtin_FUNCSIG())
59
+
60
+ #elif defined(__GNUC__)
61
+
62
+ #define TEMPEST_CURRENT_SOURCE_LOCATION () \
63
+ ::tempest::source_location::source_location (__builtin_LINE(), __builtin_COLUMN(), __builtin_FILE(), \
64
+ __PRETTY_FUNCTION__)
65
+
66
+ #endif
67
+
79
68
#endif // tempest_core_source_location_hpp
0 commit comments