mimic++ v10.0.1
Loading...
Searching...
No Matches
SourceLocation.hpp
Go to the documentation of this file.
1// Copyright Dominic (DNKpp) Koepke 2024-2026.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at
4// https://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef MIMICPP_UTILITIES_SOURCE_LOCATION_HPP
7#define MIMICPP_UTILITIES_SOURCE_LOCATION_HPP
8
9#pragma once
10
13
14#ifndef MIMICPP_DETAIL_IS_MODULE
15 #include <cstddef>
16 #include <string_view>
17
18 #ifdef MIMICPP_DETAIL_HAS_SOURCE_LOCATION
19 #include <source_location>
20 #endif
21#endif
22
24{
33 {
34 public:
35 ~SourceLocation() = default;
36
37#ifdef MIMICPP_DETAIL_HAS_SOURCE_LOCATION
43 [[nodiscard]] //
44 explicit(false) constexpr SourceLocation(
45 [[maybe_unused]] auto&&... canary,
46 std::source_location const& loc = std::source_location::current()) noexcept
47 : m_FileName{loc.file_name()},
48 m_FunctionName{loc.function_name()},
49 m_Line{loc.line()}
50 {
51 static_assert(0 == sizeof...(canary), "Do not supply custom arguments to util::SourceLocation.");
52 }
53#else
61 [[nodiscard]] //
62 explicit(false) constexpr SourceLocation(
63 [[maybe_unused]] auto&&... canary,
64 std::string_view const fileName = __builtin_FILE(),
65 std::string_view const functionName = __builtin_FUNCTION(),
66 std::size_t const line = __builtin_LINE()) noexcept
67 : m_FileName{fileName},
68 m_FunctionName{functionName},
69 m_Line{line}
70 {
71 static_assert(0 == sizeof...(canary), "Do not supply custom arguments to util::SourceLocation.");
72 }
73#endif
74
75 SourceLocation(SourceLocation const&) = default;
79
80 [[nodiscard]]
81 constexpr std::string_view file_name() const noexcept
82 {
83 return m_FileName;
84 }
85
86 [[nodiscard]]
87 constexpr std::string_view function_name() const noexcept
88 {
89 return m_FunctionName;
90 }
91
92 [[nodiscard]]
93 constexpr std::size_t line() const noexcept
94 {
95 return m_Line;
96 }
97
98 [[nodiscard]]
99 friend constexpr bool operator==(SourceLocation const& lhs, SourceLocation const& rhs) noexcept
100 {
101 return lhs.line() == rhs.line()
102 && lhs.file_name() == rhs.file_name()
103 && lhs.function_name() == rhs.function_name();
104 }
105
106 private:
107 std::string_view m_FileName;
108 std::string_view m_FunctionName;
109 std::size_t m_Line;
110 };
111}
112
113#endif
#define MIMICPP_DETAIL_MODULE_EXPORT
Definition Config.hpp:19
std::string_view const std::string_view const functionName
Definition SourceLocation.hpp:65
constexpr std::string_view function_name() const noexcept
Definition SourceLocation.hpp:87
SourceLocation & operator=(SourceLocation &&)=default
std::string_view const fileName
Definition SourceLocation.hpp:64
SourceLocation & operator=(SourceLocation const &)=default
SourceLocation(SourceLocation &&)=default
std::string_view const std::string_view const std::size_t const line
Definition SourceLocation.hpp:66
friend constexpr bool operator==(SourceLocation const &lhs, SourceLocation const &rhs) noexcept
Definition SourceLocation.hpp:99
constexpr std::string_view file_name() const noexcept
Definition SourceLocation.hpp:81
constexpr std::size_t line() const noexcept
Definition SourceLocation.hpp:93
Definition Fwd.hpp:451