-
Notifications
You must be signed in to change notification settings - Fork 0
/
vector.hpp
191 lines (157 loc) · 6.07 KB
/
vector.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#pragma once
#include <tuple>
#include <type_traits>
namespace khzmp {
//////////////////////////////////////
// //
// VECTOR //
// //
//////////////////////////////////////
struct empty_vector {};
template <class... T>
struct vector;
template <>
struct vector<> {
using head = empty_vector;
using tail = empty_vector;
using tuple_t = std::tuple<>;
static constexpr std::size_t size = 0;
};
template <class H, class... T>
struct vector<H, T...> : vector<T...> {
using head = H;
using tail = vector<T...>;
using tuple_t = std::tuple<H, T...>;
static constexpr std::size_t size = 1 + sizeof...(T);
};
//////////////////////////////////////
// //
// PUSH_BACK //
// //
//////////////////////////////////////
template <class Container, class T>
struct push_back;
template <template <class...> class Container, class T, class... Ts>
struct push_back<Container<Ts...>, T> {
using type = Container<Ts..., T>;
};
template <class Container, class T>
using push_back_t = typename push_back<Container, T>::type;
//////////////////////////////////////
// //
// PUSH_FRONT //
// //
//////////////////////////////////////
template <class Container, class T>
struct push_front;
template <template <class...> class Container, class... ContainerTs, class NewT>
struct push_front<Container<ContainerTs...>, NewT> {
using type = Container<NewT, ContainerTs...>;
};
template <class Container, class T>
using push_front_t = typename push_front<Container, T>::type;
//////////////////////////////////////
// //
// POP_BACK //
// Under Construction! //
// //
//////////////////////////////////////
// template<class Container, class T>
// struct pop_back;
//
// template <template <class...> class Container, class... ContainerTs>
// struct pop_back<Container<ContainerTs...>> {
// using type = Container<std::index_sequence<sizeof...(ContainerTs) - 1>>;
//};
//////////////////////////////////////
// //
// POP_FRONT //
// //
//////////////////////////////////////
template <class Container, class... Ts>
struct pop_front;
template <template <class...> class Container, class ContainerH,
class... ContainerTs>
struct pop_front<Container<ContainerH, ContainerTs...>> {
using type = Container<ContainerTs...>;
};
template <class Container, class... Ts>
using pop_front_t = typename pop_front<Container, Ts...>::type;
//////////////////////////////////////
// //
// FILTER_NOT //
// //
//////////////////////////////////////
template <class Container, class... Ts>
struct _filter_not_impl;
template <template <class...> class Container, class TargetT,
class... SelectedTs>
struct _filter_not_impl<Container<>, TargetT, Container<SelectedTs...>> {
using type = Container<SelectedTs...>;
};
template <template <class...> class Container, class TargetT, class ContainerH,
class... ContainerTs, class... SelectedTs>
struct _filter_not_impl<Container<ContainerH, ContainerTs...>, TargetT,
Container<SelectedTs...>>
: _filter_not_impl<
Container<ContainerTs...>, TargetT,
std::conditional_t<std::is_same_v<ContainerH, TargetT>,
Container<SelectedTs...>,
Container<SelectedTs..., ContainerH>>> {};
template <class Container, class TargetT>
struct filter_not;
template <template <class...> class Container, class... Ts, class TargetT>
struct filter_not<Container<Ts...>, TargetT> {
using type =
typename _filter_not_impl<Container<Ts...>, TargetT, Container<>>::type;
};
template <class Container, class TargetT>
using filter_not_t = typename filter_not<Container, TargetT>::type;
//////////////////////////////////////
// //
// FILTER_IF_NOT //
// Under Construction! //
// //
//////////////////////////////////////
// template <bool Pred, class...> struct filterIfNotImpl;
//
// template <bool Pred, template <class...> class Container, class... SelectedT>
// struct filterIfNotImpl<Pred, Container<>, Container<SelectedTs...>> {
// using type = Container<SelectedTs...>;
//};
//
// template <bool Pred, template <class...> class Container, class ContainerH,
// class... ContainerTs, class... SelectedTs> struct filterIfNotImpl<Pred,
// Container<ContainerH, ContainerTs...>, Container<SelectedTs...>, Pred> :
// filterIfNotImpl <
// Container<ContainerTs...>,
// std::conditional_t<
// Pred<T>,
// Container<SelectedTs...>,
// Container<SelectedTs..., ContainerH>
// >,
// TargetT
// > {};
//
// template<class...> struct filterIfNot;
//
// template <template <class...> class Container, class...Ts, class TargetT>
// struct filterIfNot<Container<Ts...>, TargetT> {
// using type = typename filterIfNot<Container<Ts...>, Container<>,
// TargetT>::type;
//};
//////////////////////////////////////
// //
// CONTAINS //
// //
//////////////////////////////////////
template <class...>
struct contains;
template <template <class...> class Container, class H, class... ContainerTs,
class TargetType>
struct contains<Container<H, ContainerTs...>, TargetType>
: std::conditional_t<std::is_same_v<H, TargetType>, std::true_type,
contains<Container<ContainerTs...>, TargetType>> {};
template <class... T>
inline constexpr bool contains_v = contains<T...>::value;
} // namespace khzmp