Type Pack 0.0.1
Loading...
Searching...
No Matches
typack.hpp
Go to the documentation of this file.
1
2#ifndef TYPACK_H
3#define TYPACK_H
4
5#include <cstddef>
6#include <type_traits>
7
9namespace ty {
10
13template<typename ...> struct pack;
14
16namespace detail {
17
21template<typename ...Ts>
22struct pack_type : std::type_identity<pack<Ts...>> {};
23
26template<typename T, bool Filter> struct filter_pack;
27
30template<typename T>
31struct filter_pack<T, true> : pack_type<T> {};
32
35template<typename T>
36struct filter_pack<T, false> : pack_type<> {};
38
41template<typename ...Ts>
42struct pack_base {
44 static constexpr auto size = sizeof...(Ts);
45
49 template<typename ...Us>
50 struct concat : pack_type<Ts..., Us...> {};
51
56 template<typename ...Us>
57 struct concat<pack<Us...>> : concat<Us...> {};
58
61 template<typename ...Us>
62 using concat_t = typename concat<Us...>::type;
63
69 template<template<typename ...> typename Trait, typename ...Us>
70 struct any : std::integral_constant<bool,
71 (Trait<Ts, Us...>::value || ...)> {};
72
77 template<template<typename ...> typename Trait, typename ...Us>
78 static constexpr auto any_v = any<Trait, Us...>::value;
79
85 template<template<typename ...> typename Trait, typename ...Us>
86 struct all : std::integral_constant<bool,
87 (Trait<Ts, Us...>::value && ...)> {};
88
93 template<template<typename ...> typename Trait, typename ...Us>
94 static constexpr auto all_v = all<Trait, Us...>::value;
95
98 template<template<typename ...> typename Tuple>
99 using into_t = Tuple<Ts...>;
100};
101
102} // namespace detail
103
105template<>
110 template<std::size_t>
111 struct out_of_bounds : std::false_type {};
112
115 template<std::size_t I>
116 struct at {
117 static_assert(out_of_bounds<I>::value, "pack index out of bounds");
118 };
120
123 template<template<typename ...> typename, typename ...>
124 struct map : detail::pack_type<> {};
125
129 template<template<typename ...> typename Mod, typename ...Ts>
130 using map_t = typename map<Mod, Ts...>::type;
131
134 template<template<typename ...> typename, typename ...>
135 struct filter : detail::pack_type<> {};
136
140 template<template<typename ...> typename Trait, typename ...Ts>
141 using filter_t = typename filter<Trait, Ts...>::type;
142};
143
147template<typename Head, typename ...Tail>
148struct pack<Head, Tail...> : detail::pack_base<Head, Tail...> {
150 using head_t = Head;
151
153 using tail_t = pack<Tail...>;
154
158 template<std::size_t I>
159 struct at : std::type_identity<
160 typename tail_t::template at<I - 1>::type> {};
161
164 template<>
165 struct at<0> : std::type_identity<Head> {};
166
169 template<std::size_t I>
170 using at_t = typename at<I>::type;
171
177 template<template<typename ...> typename Mod, typename ...Ts>
178 struct map : std::type_identity<
179 typename pack<typename Mod<Head, Ts...>::type>::template concat_t<
180 typename tail_t::template map<Mod, Ts...>::type>> {};
181
185 template<template<typename ...> typename Mod, typename ...Ts>
186 using map_t = typename map<Mod, Ts...>::type;
187
193 template<template<typename ...> typename Trait, typename ...Ts>
194 struct filter : std::type_identity<
195 typename detail::filter_pack<Head, Trait<Head, Ts...>::value>::type
196 ::template concat_t<typename tail_t
197 ::template filter<Trait, Ts...>::type>> {};
198
203 template<template<typename ...> typename Trait, typename ...Ts>
204 using filter_t = typename filter<Trait, Ts...>::type;
205};
206
209template<typename ...Ts>
210struct pack<pack<Ts...>> : pack<Ts...> {};
211
214
215} // namespace ty
216
217#endif // TYPACK_H
Type Pack.
Definition typack.hpp:9
Provides a static constant which indicates whether all types in this pack match Trait  
Definition typack.hpp:87
Provides a static constant which indicates whether any type in this pack matches Trait.
Definition typack.hpp:71
Provides a member typedef type which is this pack with Us added.
Definition typack.hpp:50
Provides common pack functionality.
Definition typack.hpp:42
typename concat< Us... >::type concat_t
Helper type which is this pack with Us added.
Definition typack.hpp:62
Tuple< Ts... > into_t
Helper type which wraps this pack's types in Tuple.
Definition typack.hpp:99
pack< Tail... > tail_t
Pack of all types in this pack, except for the first.
Definition typack.hpp:153
typename map< Mod, Ts... >::type map_t
Helper type which is all types in this pack transformed by Mod.
Definition typack.hpp:186
typename at< I >::type at_t
Helper type which is the type at pack index I.
Definition typack.hpp:170
Head head_t
First type in this pack.
Definition typack.hpp:150
typename filter< Trait, Ts... >::type filter_t
Helper type which is a pack with all types in this pack that match Trait.
Definition typack.hpp:204
Empty pack specialization.
Definition typack.hpp:106
typename map< Mod, Ts... >::type map_t
Helper type which transforms each type in this pack with Mod  
Definition typack.hpp:130
typename filter< Trait, Ts... >::type filter_t
Helper type which filters the types in this pack matching Trait.
Definition typack.hpp:141
A wrapper for a type template parameter pack.
Definition typack.hpp:13