forked from managarm/cxxshim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutility
101 lines (81 loc) · 2.25 KB
/
utility
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef _CXXSHIM_UTILITY
#define _CXXSHIM_UTILITY
#include <stddef.h>
#include <type_traits>
#ifdef CXXSHIM_INTEGRATE_GCC
#include <bits/move.h>
#endif
namespace std {
#ifndef CXXSHIM_INTEGRATE_GCC
template<typename T>
constexpr remove_reference_t<T> &&move(T &&x) noexcept {
return static_cast<remove_reference_t<T> &&>(x);
}
template<typename T>
constexpr T &&forward(remove_reference_t<T> &x) noexcept {
return static_cast<T &&>(x);
}
template<typename T>
void swap(T &x, T &y) {
T temp{move(x)};
x = move(y);
y = move(temp);
}
#endif // !defined(CXXSHIM_INTEGRATE_GCC)
template<class T, class U = T>
T exchange(T &ref, U &&v) {
T temp = std::move(ref);
ref = std::forward<U>(v);
return temp;
}
template<typename I, I... Seq>
class integer_sequence { };
template<size_t... Seq>
using index_sequence = integer_sequence<size_t, Seq...>;
namespace detail {
template<typename I, I X, I N, I... Seq>
struct _make_seq_helper {
using type = typename _make_seq_helper<I, X + 1, N, Seq..., X>::type;
};
template<typename I, I N, I... Seq>
struct _make_seq_helper<I, N, N, Seq...> {
using type = integer_sequence<I, Seq...>;
};
} // namespace detail
template<typename I, I N>
using make_integer_sequence = typename detail::_make_seq_helper<I, 0, N>::type;
template<size_t N>
using make_index_sequence = make_integer_sequence<size_t, N>;
template<typename... T>
using index_sequence_for = make_index_sequence<sizeof...(T)>;
struct source_location {
static consteval source_location current(
const char *file = __builtin_FILE(),
const char *function = __builtin_FUNCTION(),
unsigned int line = __builtin_LINE(),
// GCC 10 has all builtins except for __builtin_COLUMN.
#if __has_builtin(__builtin_COLUMN)
unsigned int column = __builtin_COLUMN()) {
#else
unsigned int column = 0) {
#endif
source_location sl;
sl.file_ = file;
sl.function_ = function;
sl.line_ = line;
sl.column_ = column;
return sl;
}
source_location() = default;
auto file() { return file_; }
auto function() { return function_; }
auto line() { return line_; }
auto column() { return column_; }
private:
const char *file_ = nullptr;
const char *function_ = nullptr;
unsigned int line_ = 0;
unsigned int column_ = 0;
};
} // namespace std
#endif // _CXXSHIM_UTILITY