DUNE PDELab (2.8)

typelist.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_COMMON_TYPELIST_HH
4#define DUNE_COMMON_TYPELIST_HH
5
6#include <type_traits>
7#include <tuple>
8#include <utility>
9
10namespace Dune {
11
30 template<class T>
31 struct MetaType {
33 using type = T;
34 };
35
84 template<class... T>
85 using TypeList = std::tuple<MetaType<T>...>;
86
87
88
97 template<class T>
98 struct IsTypeList : std::false_type {};
99
105 template<class... T>
106 struct IsTypeList<TypeList<T...> > : std::true_type {};
107
108
109
118 template<class T>
119 struct IsEmptyTypeList : std::is_same<T, TypeList<> > {};
120
121
122
123 template<class T>
124 struct TypeListSize {};
125
134 template<class... T>
135 struct TypeListSize<TypeList<T...>> : std::integral_constant<std::size_t, sizeof...(T)> {};
136
137
138
139 template<std::size_t i, class T>
140 struct TypeListElement {};
141
147 template<std::size_t i, class... T>
148 struct TypeListElement<i, TypeList<T...>>
149 {
155 using type = typename std::tuple_element<i, std::tuple<T...>>::type;
156
162 using Type = type;
163 };
164
168 template<std::size_t i, class T>
169 using TypeListEntry_t = typename TypeListElement<i, T>::type;
170
171 namespace Impl {
172
173 template<template<class...> class Target, class ToDoList, class... Processed>
174 struct UniqueTypesHelper;
175
176 template<template<class...> class Target, class... Processed>
177 struct UniqueTypesHelper<Target, TypeList<>, Processed...>
178 {
179 using type = Target<Processed...>;
180 };
181
182 template<template<class...> class Target, class T0, class... T, class... Processed>
183 struct UniqueTypesHelper<Target, TypeList<T0, T...>, Processed...>
184 {
185 using type = std::conditional_t<
186 std::disjunction<std::is_same<T0, Processed>...>::value,
187 typename UniqueTypesHelper<Target, TypeList<T...>, Processed...>::type,
188 typename UniqueTypesHelper<Target, TypeList<T...>, T0, Processed...>::type>;
189 };
190
191 // Helper for unpacking Dune::TypeList
192 template<template<class...> class Target, class TL>
193 struct UnpackTypeList;
194
195 template<template<class...> class Target, class... T>
196 struct UnpackTypeList<Target, Dune::TypeList<T...>>
197 {
198 using type = Target<T...>;
199 };
200
201 } // namespace Impl
202
207 template<template<class...> class Target, class TL>
208 using UnpackTypeList_t = typename Impl::UnpackTypeList<Target, TL>::type;
209
217 template<template<class...> class Target, class... T>
218 using UniqueTypes_t = typename Impl::UniqueTypesHelper<Target, TypeList<T...>>::type;
219
225 template<class NonUniqueTypeList>
226 using UniqueTypeList_t = typename Impl::UniqueTypesHelper<TypeList, NonUniqueTypeList>::type;
227
233 template<class... T>
234 constexpr auto uniqueTypeList(TypeList<T...> list)
235 {
236 return typename Impl::UniqueTypesHelper<TypeList, TypeList<T...>>::type{};
237 }
238
239
240
241} // namespace Dune
242
243#endif // DUNE_COMMON_TYPELIST_HH
std::tuple< MetaType< T >... > TypeList
A simple type list.
Definition: typelist.hh:85
Dune namespace.
Definition: alignedallocator.hh:11
typename Impl::UnpackTypeList< Target, TL >::type UnpackTypeList_t
Unpack Dune::TypeList.
Definition: typelist.hh:208
constexpr auto uniqueTypeList(TypeList< T... > list)
Remove duplicates from a Dune::TypeList.
Definition: typelist.hh:234
typename Impl::UniqueTypesHelper< Target, TypeList< T... > >::type UniqueTypes_t
Remove duplicates from a list of types.
Definition: typelist.hh:218
typename Impl::UniqueTypesHelper< TypeList, NonUniqueTypeList >::type UniqueTypeList_t
Remove duplicates from a Dune::TypeList.
Definition: typelist.hh:226
typename TypeListElement< i, T >::type TypeListEntry_t
Shortcut for TypeListElement<i, T>::type;.
Definition: typelist.hh:169
Check if given type is an empty TypeList.
Definition: typelist.hh:119
Check if given type is a TypeList.
Definition: typelist.hh:98
A type that refers to another type.
Definition: typelist.hh:31
T type
The referred-to type.
Definition: typelist.hh:33
typename std::tuple_element< i, std::tuple< T... > >::type type
Export type of i-th element in TypeList.
Definition: typelist.hh:155
type Type
Export type of i-th element in TypeList.
Definition: typelist.hh:162
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 24, 22:29, 2024)