Common System 0.2.0
Common interfaces and patterns for system integration
Loading...
Searching...
No Matches
source_location.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
18#pragma once
19
21
22#if KCENON_HAS_SOURCE_LOCATION
23 #include <source_location>
24#endif
25
26namespace kcenon::common {
27
28#if KCENON_HAS_SOURCE_LOCATION
29 // Use std::source_location when available (C++20)
30 using source_location = std::source_location;
31#else
32 // Custom implementation for C++17 using compiler builtins
33 struct source_location {
34 public:
35 // Prevent accidental copying of the default argument
36 constexpr source_location(
37 const char* file = __builtin_FILE(),
38 const char* function = __builtin_FUNCTION(),
39 int line = __builtin_LINE()
40 ) noexcept
41 : file_(file), function_(function), line_(line), column_(0) {}
42
43 constexpr const char* file_name() const noexcept { return file_; }
44 constexpr const char* function_name() const noexcept { return function_; }
45 constexpr int line() const noexcept { return line_; }
46 constexpr int column() const noexcept { return column_; }
47
48 // Factory method to create a source_location at the call site
49 static constexpr source_location current(
50 const char* file = __builtin_FILE(),
51 const char* function = __builtin_FUNCTION(),
52 int line = __builtin_LINE()
53 ) noexcept {
54 return source_location(file, function, line);
55 }
56
57 private:
58 const char* file_;
59 const char* function_;
60 int line_;
62 };
63#endif
64
65} // namespace kcenon::common
Unified feature flags header for common_system.
kcenon::common::source_location source_location
Core interfaces.
Definition adapter.h:21
C++17-compatible source_location implementation using compiler builtins.
Definition utils.cppm:54
constexpr source_location(const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE()) noexcept
static constexpr source_location current(const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE()) noexcept
constexpr int line() const noexcept
constexpr int column() const noexcept
constexpr const char * file_name() const noexcept
constexpr const char * function_name() const noexcept