-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhelpers.hpp
66 lines (44 loc) · 1.4 KB
/
helpers.hpp
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
#if !defined(CALLABLE_HELPERS_HPP_INCLUDED)
#define CALLABLE_HELPERS_HPP_INCLUDED
#include <cstddef>
namespace detail {
/** Remove reference and cv qualification */
template<typename T>
using remove_cvref_t = typename std::remove_cv< typename std::remove_reference<T>::type >::type;
/** Count the number of types given to the template */
template<typename... Types>
struct types_count;
template<>
struct types_count<> {
static constexpr std::size_t value = 0;
};
template<typename Type, typename... Types>
struct types_count<Type, Types...> {
static constexpr std::size_t value = types_count<Types...>::value + 1;
};
/** Get the nth type given to the template */
template<std::size_t n, typename... Types>
struct types_n;
template<std::size_t N, typename Type, typename... Types>
struct types_n<N, Type, Types...> : types_n<N-1, Types...> {
};
template<typename Type, typename... Types>
struct types_n<0, Type, Types...> {
typedef Type type;
};
/** Test if a type is in a list given types */
template<typename Q, typename... Ts>
struct types_has;
template<typename Q>
struct types_has<Q> {
static constexpr bool value = false;
};
template<typename Q, typename... Ts>
struct types_has<Q, Q, Ts...> {
static constexpr bool value = true;
};
template<typename Q, typename T, typename... Ts>
struct types_has<Q, T, Ts...> : types_has<Q, Ts...> {
};
} // namespace detail
#endif // CALLABLE_HELPERS_HPP_INCLUDED