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 <type_traits>
30#include <utility>
31
32namespace join
33{
37 template <typename... Ts>
38 struct overload;
39
43 template <>
44 struct overload<>
45 {
46 void operator() () const;
47 };
48
52 template <typename First, typename... Ts>
53 struct overload<First, Ts...> : overload<Ts...>
54 {
55 using overload<Ts...>::operator();
56
57 std::type_identity<First> operator() (First) const;
58 };
59
63 template <typename... Ts>
64 struct overload<void, Ts...> : overload<Ts...>
65 {
66 using overload<Ts...>::operator();
67
68 std::type_identity<void> operator() () const;
69 };
70
74 template <typename T, typename... Ts>
75 using match_t = typename std::invoke_result_t<overload<Ts...>, T>::type;
76
80 template <typename T, typename... Ts>
81 inline constexpr std::size_t find_index_v = 0;
82
86 template <typename T, typename First, typename... Ts>
87 inline constexpr std::size_t find_index_v<T, First, Ts...> =
88 std::is_same_v<T, First> ? 0 : find_index_v<T, Ts...> + 1;
89
93 template <typename T, typename... Ts>
94 inline constexpr std::size_t count_v = (std::size_t{0} + ... + std::is_same_v<T, Ts>);
95
99 template <typename T, typename... Ts>
100 inline constexpr bool is_unique_v = count_v<T, Ts...> == 1;
101}
102
103#endif
Definition acceptor.hpp:32
constexpr std::size_t count_v
count the number of time a type appears in a parameter pack.
Definition traits.hpp:94
constexpr std::size_t find_index_v
get element position in a parameter pack according its type.
Definition traits.hpp:81
constexpr bool is_unique_v
check if a type only appears one time in a parameter pack.
Definition traits.hpp:100
typename std::invoke_result_t< overload< Ts... >, T >::type match_t
find a type that match one of the alternatives of a parameter pack.
Definition traits.hpp:75
overload resolution.
Definition traits.hpp:38