-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper_classes.h
189 lines (138 loc) · 6.03 KB
/
helper_classes.h
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#pragma once
#include <exception>
#include <type_traits>
template <typename... Args>
struct variant;
template <typename T>
struct variant_size;
template <typename... Types>
struct variant_size<variant<Types...>> : std::integral_constant<std::size_t, sizeof...(Types)> {};
template <typename T>
struct variant_size<T const> : std::integral_constant<std::size_t, variant_size<T>::value> {};
template <typename T>
struct variant_size<T volatile> : std::integral_constant<std::size_t, variant_size<T>::value> {};
template <typename T>
inline constexpr std::size_t variant_size_v = variant_size<T>::value;
template <std::size_t I, typename T>
struct variant_alternative;
template <std::size_t I, typename... Types>
struct type_by_index_imp;
template <std::size_t Index, typename Head, typename... Tail>
struct type_by_index_imp<Index, Head, Tail...> {
using value = typename type_by_index_imp<Index - 1, Tail...>::value;
};
template <typename Head, typename... Tail>
struct type_by_index_imp<0, Head, Tail...> {
using value = Head;
};
template <std::size_t Index, typename... Types>
requires(Index < sizeof...(Types)) using type_by_index_v = typename type_by_index_imp<Index, Types...>::value;
template <std::size_t I, typename Head, typename... Tail>
struct variant_alternative<I, variant<Head, Tail...>> {
using type = type_by_index_v<I, Head, Tail...>;
};
template <std::size_t I, typename T>
struct variant_alternative<I, const T> : variant_alternative<I, T> {
using type = typename variant_alternative<I, T>::type const;
};
template <std::size_t I, typename T>
struct variant_alternative<I, volatile T> : variant_alternative<I, T> {
using type = typename variant_alternative<I, T>::type volatile;
};
template <std::size_t I, typename T>
struct variant_alternative<I, const volatile T> : variant_alternative<I, T> {
using type = typename variant_alternative<I, T>::type const volatile;
};
template <size_t I, typename T>
using variant_alternative_t = typename variant_alternative<I, T>::type;
template <typename... Types>
concept all_is_copy_constructible_v = (std::is_copy_constructible_v<Types> && ...);
template <typename... Types>
concept all_is_trivially_copy_constructible_v = (std::is_trivially_copy_constructible_v<Types> && ...);
template <typename... Types>
concept all_is_trivially_move_constructible_v = (std::is_trivially_move_constructible_v<Types> && ...);
template <typename... Types>
concept all_is_move_constructible_v = (std::is_move_constructible_v<Types> && ...);
template <typename... Types>
concept all_is_nothrow_move_constructible_v = (std::is_nothrow_move_constructible_v<Types> && ...);
template <typename... Types>
concept all_is_nothrow_copy_constructible_v = (std::is_nothrow_copy_constructible_v<Types> && ...);
template <typename... Types>
concept all_is_nothrow_move_assignable_v = (std::is_nothrow_move_assignable_v<Types> && ...);
template <typename... Types>
concept all_is_nothrow_copy_assignable_v = (std::is_nothrow_copy_assignable_v<Types> && ...);
template <typename... Types>
concept all_is_trivially_destructible_v = (std::is_trivially_destructible_v<Types> && ...);
template <typename... Types>
concept all_is_trivially_copy_assignable_v = (std::is_trivially_copy_assignable_v<Types> && ...);
template <typename... Types>
concept all_is_move_assignable_v = (std::is_move_assignable_v<Types> && ...);
template <typename... Types>
concept all_is_trivially_move_assignable_v = (std::is_trivially_move_assignable_v<Types> && ...);
template <typename... Types>
concept all_is_copy_assignable_v = (std::is_copy_assignable_v<Types> && ...);
template <typename... Args>
struct count {
static constexpr std::size_t value = 0;
};
template <typename T, typename Head, typename... Tail>
struct count<T, Head, Tail...> {
constexpr static std::size_t value = std::is_same_v<T, Head> + count<T, Tail...>::value;
};
template <typename T, typename... Types>
concept exactly_once = (count<T, Types...>::value == 1);
template <typename T, typename... Args>
struct index_by_type_impl {
static constexpr std::size_t value = 0;
};
template <typename T, typename Head, typename... Tail>
struct index_by_type_impl<T, Head, Tail...> {
static constexpr std::size_t value = std::is_same_v<T, Head> ? 0 : index_by_type_impl<T, Tail...>::value + 1;
};
template <typename T, typename... Args>
inline constexpr std::size_t index_by_type_v = index_by_type_impl<T, Args...>::value;
struct in_place_t {
explicit in_place_t() = default;
};
inline constexpr in_place_t in_place{};
template <typename T>
struct in_place_type_t {
explicit in_place_type_t() = default;
};
template <typename T>
inline constexpr in_place_type_t<T> in_place_type{};
template <std::size_t I>
struct in_place_index_t {
explicit in_place_index_t() = default;
};
template <std::size_t I>
inline constexpr in_place_index_t<I> in_place_index{};
inline constexpr std::size_t variant_npos = -1;
template <typename T, typename Type>
concept possible_create = requires(T && t) {
Type{std::forward<T>(t)};
};
template <typename T, typename Type>
concept possible_fuction = possible_create<T, Type[]>;
struct bad_variant_access : std::exception {
bad_variant_access() noexcept {}
const char* what() const noexcept override {
return response;
}
private:
const char* response = "bad_variant_access";
};
template <typename... Args>
concept is_all_trivially_destructible_v = (std::is_trivially_destructible_v<Args> && ...);
template <std::size_t N, typename T, typename Type, typename... Types>
struct get_index_to_construct : get_index_to_construct<N + 1, T, Types...> {
using get_index_to_construct<N + 1, T, Types...>::get_index;
constexpr std::integral_constant<std::size_t, N> get_index(Type) requires(possible_fuction<T, Type>);
};
template <std::size_t N, typename T, typename Type>
struct get_index_to_construct<N, T, Type> {
constexpr std::integral_constant<std::size_t, N> get_index(Type) requires(possible_fuction<T, Type>);
};
template <typename T, typename... Types>
using ind_to_construct = decltype(get_index_to_construct<0, T, Types...>().get_index(std::declval<T>()));
struct empty_class {};