xtd 0.2.0
__xtd_source_location.hpp
Go to the documentation of this file.
1
3#pragma once
5#define __XTD_STD_INTERNAL__
7#undef __XTD_STD_INTERNAL__
8
9#if defined(__xtd__cpp_lib_source_location)
10#include <source_location>
11using __xtd_source_location__ = std::source_location;
12#else
13// Fallback implementation for std::source_location for compatibility reasons.
14//
15// Although std::source_location is part of C++20 and supported in recent compiler versions,
16// the support on Apple platforms (Xcode/Clang) is still incomplete or inconsistent,
17// especially on versions prior to Xcode 15.4.
18//
19// This fallback uses compiler builtins (__builtin_FILE, __builtin_LINE, etc.) to
20// provide similar functionality without relying on std::source_location.
21//
22// We keep this fallback to ensure compatibility with older toolchains and to avoid
23// breaking CI or user builds when newer Xcode versions are not available.
24//
25// Once support for std::source_location becomes reliable across all supported
26// Xcode versions, this fallback can be removed.
27//
28// See: https://developer.apple.com/forums/thread/713513 for related discussion.
29//
30#include <cstdint>
31#include <memory>
32
33class __xtd_source_location__ {
34public:
35 const char* file_name() const noexcept {return data_->file;}
36 uint32_t line() const noexcept {return data_->line;}
37 const char* function_name() const noexcept {return data_->func;}
38 uint32_t column() const noexcept {return data_->column;}
39
40 static __xtd_source_location__ current(const char* file = __builtin_FILE(), uint32_t line = __builtin_LINE(), const char* func = __builtin_FUNCTION(), uint32_t column = __builtin_COLUMN()) noexcept {
41 auto csl = __xtd_source_location__ {};
42 *csl.data_ = {file, line, func, column};
43 return csl;
44 }
45
46private:
47 struct data {
48 const char* file;
49 uint32_t line;
50 const char* func;
51 uint32_t column;
52 };
53 std::shared_ptr<data> data_ = std::make_shared<data>();
54};
55#endif
Contains __xtd_std_version definitions.
xtd::delegate< result_t(arguments_t... arguments)> func
Represents a delegate that has variables parameters and returns a value of the type specified by the ...
Definition func.hpp:27
@ current
Specifies the current position within a stream.
Definition seek_origin.hpp:20
constexpr const_pointer data() const noexcept
Gets direct access to the underlying contiguous storage.
Definition read_only_span.hpp:201