join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
traits.hpp
Go to the documentation of this file.
1
25#ifndef JOIN_CORE_TRAITS_HPP
26#define JOIN_CORE_TRAITS_HPP
27
28// C++.
29#include <utility>
30#include <type_traits>
31#include <bits/enable_special_members.h>
32
33namespace join
34{
39 {
40 explicit in_place_t () = default;
41 };
42
46 template <typename T>
48 {
49 explicit in_place_type_t () = default;
50 };
51
55 template <std::size_t I>
57 {
58 explicit in_place_index_t () = default;
59 };
60
64 template <typename T>
65 struct identity
66 {
67 using type = T;
68 };
69
73 template <typename T>
74 using identity_t = typename identity<T>::type;
75
79 template <typename... Ts>
80 struct overload;
81
85 template <>
86 struct overload<>
87 {
88 void operator() () const;
89 };
90
94 template <typename First, typename... Ts>
95 struct overload<First, Ts...> : overload<Ts...>
96 {
97 using overload<Ts...>::operator();
98
99 identity<First> operator() (First) const;
100 };
101
105 template <typename... Ts>
106 struct overload<void, Ts...> : overload<Ts...>
107 {
108 using overload<Ts...>::operator();
109
110 identity<void> operator() () const;
111 };
112
116 template <typename T, typename... Ts>
117 using match_t = typename std::result_of_t<overload<Ts...> (T)>::type;
118
122 template <typename T, typename... Ts>
123 struct find_index : std::integral_constant<std::size_t, 0>
124 {
125 };
126
130 template <typename T, typename First, typename... Ts>
131 struct find_index<T, First, Ts...>
132 : std::integral_constant<std::size_t, std::is_same<T, First>::value ? 0 : find_index<T, Ts...>::value + 1>
133 {
134 };
135
139 template <std::size_t I, typename T, typename... Ts>
141 {
142 using type = typename find_element<I - 1, Ts...>::type;
143 };
144
148 template <typename T, typename... Ts>
149 struct find_element<0, T, Ts...>
150 {
151 using type = T;
152 };
153
157 template <std::size_t I, typename... Ts>
158 using find_element_t = typename find_element<I, Ts...>::type;
159
163 template <std::size_t I, typename T>
164 struct find_element<I, const T>
165 {
166 using type = std::add_const_t<find_element_t<I, T>>;
167 };
168
172 template <std::size_t I, typename T>
173 struct find_element<I, volatile T>
174 {
175 using type = std::add_volatile_t<find_element_t<I, T>>;
176 };
177
181 template <std::size_t I, typename T>
182 struct find_element<I, const volatile T>
183 {
184 using type = std::add_cv_t<find_element_t<I, T>>;
185 };
186
190 template <typename T, typename... Ts>
191 struct is_alternative : std::integral_constant<bool, false>
192 {
193 };
194
198 template <typename T, typename First, typename... Ts>
199 struct is_alternative<T, First, Ts...>
200 : std::integral_constant<bool, std::is_same<T, First>::value || is_alternative<T, Ts...>::value>
201 {
202 };
203
207 template <std::size_t I, typename... Ts>
208 struct is_index : std::integral_constant < bool,
209 I<sizeof...(Ts)>
210 {
211 };
212
216 template <typename T, typename... Ts>
217 struct count : std::integral_constant<std::size_t, 0>
218 {
219 };
220
224 template <typename T, typename First, typename... Ts>
225 struct count<T, First, Ts...>
226 : std::integral_constant<std::size_t, count<T, Ts...>::value + std::is_same<T, First>::value>
227 {
228 };
229
233 template <typename T, typename... Ts>
234 struct is_unique : std::integral_constant<bool, count<T, Ts...>::value == 1>
235 {
236 };
237
241 template <bool... Ts>
242 using all = std::is_same<std::integer_sequence<bool, true, Ts...>, std::integer_sequence<bool, Ts..., true>>;
243
247 template <typename... Ts>
248 struct are_copy_constructible : std::integral_constant<bool, all<std::is_copy_constructible<Ts>::value...>::value>
249 {
250 };
251
255 template <typename... Ts>
256 struct are_move_constructible : std::integral_constant<bool, all<std::is_move_constructible<Ts>::value...>::value>
257 {
258 };
259
263 template <typename... Ts>
264 struct are_copy_assignable
265 : std::integral_constant<bool, are_copy_constructible<Ts...>::value && are_move_constructible<Ts...>::value &&
266 all<std::is_copy_assignable<Ts>::value...>::value>
267 {
268 };
269
273 template <typename... Ts>
274 struct are_move_assignable : std::integral_constant<bool, are_move_constructible<Ts...>::value &&
275 all<std::is_move_assignable<Ts>::value...>::value>
276 {
277 };
278
282 struct EnableDefaultTag
283 {
284 explicit constexpr EnableDefaultTag () = default;
285 };
286
290 template <bool _Switch, typename _Tag = void>
291 struct EnableDefault
292 {
293 constexpr EnableDefault () noexcept = default;
294 constexpr EnableDefault (EnableDefault const&) noexcept = default;
295 constexpr EnableDefault (EnableDefault&&) noexcept = default;
296
297 constexpr explicit EnableDefault (EnableDefaultTag)
298 {
299 }
300
301 EnableDefault& operator= (EnableDefault const&) noexcept = default;
302 EnableDefault& operator= (EnableDefault&&) noexcept = default;
303 };
304
308 template <typename _Tag>
309 struct EnableDefault<false, _Tag>
310 {
311 constexpr EnableDefault () noexcept = delete;
312 constexpr EnableDefault (EnableDefault const&) noexcept = default;
313 constexpr EnableDefault (EnableDefault&&) noexcept = default;
314
315 constexpr explicit EnableDefault (EnableDefaultTag)
316 {
317 }
318
319 EnableDefault& operator= (EnableDefault const&) noexcept = default;
320 EnableDefault& operator= (EnableDefault&&) noexcept = default;
321 };
322}
323
324#endif
Definition acceptor.hpp:32
typename find_element< I, Ts... >::type find_element_t
get element type in a parameter pack according its position.
Definition traits.hpp:158
typename identity< T >::type identity_t
return type unchanged.
Definition traits.hpp:74
typename std::result_of_t< overload< Ts... >(T)>::type match_t
find a type that match one of the alternatives of a parameter pack.
Definition traits.hpp:117
T type
Definition traits.hpp:151
std::add_const_t< find_element_t< I, T > > type
Definition traits.hpp:166
std::add_cv_t< find_element_t< I, T > > type
Definition traits.hpp:184
std::add_volatile_t< find_element_t< I, T > > type
Definition traits.hpp:175
get element type in a parameter pack according its position.
Definition traits.hpp:141
typename find_element< I - 1, Ts... >::type type
Definition traits.hpp:142
get element position in a parameter pack according its type.
Definition traits.hpp:124
return type unchanged.
Definition traits.hpp:66
T type
Definition traits.hpp:67
disambiguation tag to indicate that the contained object should be constructed in-place.
Definition traits.hpp:57
disambiguation tag to indicate that the contained object should be constructed in-place.
Definition traits.hpp:39
in_place_t()=default
disambiguation tag to indicate that the contained object should be constructed in-place.
Definition traits.hpp:48
check if a type exists in a parameter pack.
Definition traits.hpp:192
overload resolution.
Definition traits.hpp:80