-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Traits.hpp
84 lines (67 loc) · 2.16 KB
/
Traits.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright (c) libASPL authors
// Licensed under MIT
#pragma once
#include <tuple>
#include <type_traits>
#include <vector>
namespace aspl {
template <typename T>
struct is_vector : public std::false_type
{
};
template <typename T, typename A>
struct is_vector<std::vector<T, A>> : public std::true_type
{
};
template <typename Func>
class method_return_type
{
template <typename Class, typename Return, typename... Args>
static auto return_of(Return (Class::*)(Args...))
{
return std::declval<Return>();
}
template <typename Class, typename Return, typename... Args>
static auto return_of(Return (Class::*)(Args...) const)
{
return std::declval<Return>();
}
template <typename Class, typename Return, typename... Args>
static auto return_of(Return (Class::*)(Args...) const volatile)
{
return std::declval<Return>();
}
public:
using type = std::remove_cv_t<
std::remove_reference_t<decltype(return_of(std::declval<Func>()))>>;
};
template <typename Method>
using method_return_type_t = typename method_return_type<Method>::type;
template <typename Func, size_t ArgIndex>
class method_argument_type
{
template <typename... Args>
using nth_argument_t =
typename std::tuple_element<ArgIndex, std::tuple<Args...>>::type;
template <typename Class, typename Return, typename... Args>
static auto nth_argument_of(Return (Class::*)(Args...))
{
return std::declval<nth_argument_t<Args...>>();
}
template <typename Class, typename Return, typename... Args>
static auto nth_argument_of(Return (Class::*)(Args...) const)
{
return std::declval<nth_argument_t<Args...>>();
}
template <typename Class, typename Return, typename... Args>
static auto nth_argument_of(Return (Class::*)(Args...) const volatile)
{
return std::declval<nth_argument_t<Args...>>();
}
public:
using type = std::remove_cv_t<
std::remove_reference_t<decltype(nth_argument_of(std::declval<Func>()))>>;
};
template <typename Method, size_t ArgIndex>
using method_argument_type_t = typename method_argument_type<Method, ArgIndex>::type;
} // namespace aspl