-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrapper.hpp
127 lines (101 loc) · 2.04 KB
/
wrapper.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#ifndef _DPCB_WRAPPER_HPP_
#define _DPCB_WRAPPER_HPP_
#include <utility>
#include <tuple>
namespace DPCB{
namespace detail{
template<std::size_t I, class Head, class ...Rs>
class retrieve_type
{
public:
using type = typename retrieve_type<I-1, Rs...>::type;
};
template<class Head, class ...Rs>
class retrieve_type<0, Head, Rs...>
{
public:
using type = Head;
};
}
template<typename ...Ts>
class wrapper_any
{
protected:
template<int Index, bool IsNeg=(Index<0)>
class get_type
{
public:
using type = typename detail::retrieve_type<Index, Ts...>::type;
};
template<int Index>
class get_type<Index, true>
{
public:
using type = typename detail::retrieve_type<Index+sizeof...(Ts), Ts...>::type;
};
public:
template<int Index>
using type = typename get_type<Index>::type;
};
template<>
class wrapper_any<>
{
};
template<typename T>
class wrapper_class
{
static_assert(!std::is_class_v<T>, "This wrapper does not apply to a class type");
public:
T data;
template<typename ...Args>
wrapper_class(Args &&...args) : data(std::forward<Args>(args)...)
{
}
operator T() const
{
return data;
}
};
namespace detail{
template<class, class T>
class wrapper_label_impl : public T
{
public:
using type = T;
using T::T;
};
}
template<class Label, typename T>
using wrapper_label = detail::wrapper_label_impl<
Label,
std::conditional_t<std::is_class_v<T>, T, wrapper_class<T>>
>;
template<typename ...Ts>
class wrapper_base : public Ts...
{
public:
template<std::size_t Index>
using get_base = typename detail::retrieve_type<Index, Ts...>::type;
};
template<class T>
class wrapper_construct_from_tuple : public T
{
public:
template<std::size_t ...I, class Tuple>
wrapper_construct_from_tuple(std::index_sequence<I...>, Tuple &&tp)
: T(std::get<I>(std::forward<Tuple>(tp))...)
{
}
template<class Tuple>
wrapper_construct_from_tuple(Tuple &&tp) :
wrapper_construct_from_tuple(
std::make_index_sequence<
std::tuple_size_v<std::remove_reference_t<Tuple>>
>(),
std::forward<Tuple>(tp)
)
{
}
};
}
#endif //_DPCB_WRAPPER_HPP_