Distributed Ranges
Loading...
Searching...
No Matches
source_location.hpp
1// SPDX-FileCopyrightText: Intel Corporation
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef NOSTD_SOURCE_LOCATION_HPP
6#define NOSTD_SOURCE_LOCATION_HPP
7
8#pragma once
9
10#include <cstdint>
11
12namespace nostd {
14public:
15#if not defined(__apple_build_version__) and defined(__clang__) and \
16 (__clang_major__ >= 9)
17 static constexpr source_location
18 current(const char *fileName = __builtin_FILE(),
19 const char *functionName = __builtin_FUNCTION(),
20 const uint_least32_t lineNumber = __builtin_LINE(),
21 const uint_least32_t columnOffset = __builtin_COLUMN()) noexcept
22#elif defined(__GNUC__) and \
23 (__GNUC__ > 4 or (__GNUC__ == 4 and __GNUC_MINOR__ >= 8))
24 static constexpr source_location
25 current(const char *fileName = __builtin_FILE(),
26 const char *functionName = __builtin_FUNCTION(),
27 const uint_least32_t lineNumber = __builtin_LINE(),
28 const uint_least32_t columnOffset = 0) noexcept
29#else
30 static constexpr source_location
31 current(const char *fileName = "unsupported",
32 const char *functionName = "unsupported",
33 const uint_least32_t lineNumber = 0,
34 const uint_least32_t columnOffset = 0) noexcept
35#endif
36 {
37 return source_location(fileName, functionName, lineNumber, columnOffset);
38 }
39
40 source_location(const source_location &) = default;
41 source_location(source_location &&) = default;
42
43 constexpr const char *file_name() const noexcept { return fileName; }
44
45 constexpr const char *function_name() const noexcept { return functionName; }
46
47 constexpr uint_least32_t line() const noexcept { return lineNumber; }
48
49 constexpr std::uint_least32_t column() const noexcept { return columnOffset; }
50
51private:
52 constexpr source_location(const char *fileName, const char *functionName,
53 const uint_least32_t lineNumber,
54 const uint_least32_t columnOffset) noexcept
55 : fileName(fileName), functionName(functionName), lineNumber(lineNumber),
56 columnOffset(columnOffset) {}
57
58 const char *fileName;
59 const char *functionName;
60 const std::uint_least32_t lineNumber;
61 const std::uint_least32_t columnOffset;
62};
63} // namespace nostd
64
65#endif
Definition: source_location.hpp:13