join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
traits.hpp
Go to the documentation of this file.
1
25#ifndef __JOIN_TRAITS_HPP__
26#define __JOIN_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>
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...> : std::integral_constant <std::size_t, std::is_same <T, First>::value ? 0 : find_index <T, Ts...>::value + 1>
132 {
133 };
134
138 template <std::size_t I, typename T, typename... Ts>
140 {
141 using type = typename find_element <I - 1, Ts...>::type;
142 };
143
147 template <typename T, typename... Ts>
148 struct find_element <0, T, Ts...>
149 {
150 using type = T;
151 };
152
156 template <std::size_t I, typename... Ts>
157 using find_element_t = typename find_element <I, Ts...>::type;
158
162 template <std::size_t I, typename T>
163 struct find_element <I, const T>
164 {
165 using type = std::add_const_t <find_element_t <I, T>>;
166 };
167
171 template <std::size_t I, typename T>
172 struct find_element <I, volatile T>
173 {
174 using type = std::add_volatile_t <find_element_t <I, T>>;
175 };
176
180 template <std::size_t I, typename T>
181 struct find_element <I, const volatile T>
182 {
183 using type = std::add_cv_t <find_element_t <I, T>>;
184 };
185
189 template <typename T, typename... Ts>
190 struct is_alternative : std::integral_constant <bool, false>
191 {
192 };
193
197 template <typename T, typename First, typename... Ts>
198 struct is_alternative <T, First, Ts...> : std::integral_constant <bool, std::is_same <T, First>::value || is_alternative <T, Ts...>::value>
199 {
200 };
201
205 template <std::size_t I, typename... Ts>
206 struct is_index : std::integral_constant <bool, I < sizeof... (Ts)>
207 {
208 };
209
213 template <typename T, typename... Ts>
214 struct count : std::integral_constant <std::size_t, 0>
215 {
216 };
217
221 template <typename T, typename First, typename... Ts>
222 struct count <T, First, Ts...> : std::integral_constant <std::size_t, count <T, Ts...>::value + std::is_same <T, First>::value>
223 {
224 };
225
229 template <typename T, typename... Ts>
230 struct is_unique : std::integral_constant <bool, count <T, Ts...>::value == 1>
231 {
232 };
233
237 template <bool... Ts>
238 using all = std::is_same <std::integer_sequence <bool, true, Ts...>, std::integer_sequence <bool, Ts..., true>>;
239
243 template <typename... Ts>
244 struct are_copy_constructible : std::integral_constant <bool, all <std::is_copy_constructible <Ts>::value...>::value>
245 {
246 };
247
251 template <typename... Ts>
252 struct are_move_constructible : std::integral_constant <bool, all <std::is_move_constructible <Ts>::value...>::value>
253 {
254 };
255
259 template <typename... Ts>
260 struct are_copy_assignable : std::integral_constant <bool, are_copy_constructible <Ts...>::value &&
261 are_move_constructible <Ts...>::value && all <std::is_copy_assignable <Ts>::value...>::value>
262 {
263 };
264
268 template <typename... Ts>
269 struct are_move_assignable : std::integral_constant <bool, are_move_constructible <Ts...>::value &&
270 all <std::is_move_assignable <Ts>::value...>::value>
271 {
272 };
273
277 struct EnableDefaultTag
278 {
279 explicit constexpr EnableDefaultTag () = default;
280 };
281
285 template <bool _Switch, typename _Tag = void>
286 struct EnableDefault
287 {
288 constexpr EnableDefault () noexcept = default;
289 constexpr EnableDefault (EnableDefault const&) noexcept = default;
290 constexpr EnableDefault (EnableDefault&&) noexcept = default;
291 constexpr explicit EnableDefault (EnableDefaultTag) {}
292 EnableDefault& operator= (EnableDefault const&) noexcept = default;
293 EnableDefault& operator= (EnableDefault&&) noexcept = default;
294 };
295
299 template <typename _Tag>
300 struct EnableDefault <false, _Tag>
301 {
302 constexpr EnableDefault () noexcept = delete;
303 constexpr EnableDefault (EnableDefault const&) noexcept = default;
304 constexpr EnableDefault (EnableDefault&&) noexcept = default;
305 constexpr explicit EnableDefault (EnableDefaultTag) {}
306 EnableDefault& operator= (EnableDefault const&) noexcept = default;
307 EnableDefault& operator= (EnableDefault&&) noexcept = default;
308 };
309}
310
311#endif
Definition acceptor.hpp:32
typename identity< T >::type identity_t
return type unchanged.
Definition traits.hpp:74
typename find_element< I, Ts... >::type find_element_t
get element type in a parameter pack according its position.
Definition traits.hpp:157
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:150
std::add_const_t< find_element_t< I, T > > type
Definition traits.hpp:165
std::add_cv_t< find_element_t< I, T > > type
Definition traits.hpp:183
std::add_volatile_t< find_element_t< I, T > > type
Definition traits.hpp:174
get element type in a parameter pack according its position.
Definition traits.hpp:140
typename find_element< I - 1, Ts... >::type type
Definition traits.hpp:141
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:191
identity< First > operator()(First) const
identity< void > operator()() const
void operator()() const
overload resolution.
Definition traits.hpp:80