Dune Core Modules (2.10.0)

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// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5#ifndef DUNE_COMMON_TYPELIST_HH
6#define DUNE_COMMON_TYPELIST_HH
7
8#include <type_traits>
9#include <tuple>
10#include <utility>
11
12namespace Dune {
13
32 template<class T>
33 struct MetaType {
35 using type = T;
36 };
37
86 template<class... T>
87 using TypeList = std::tuple<MetaType<T>...>;
88
89
90
99 template<class T>
100 struct IsTypeList : std::false_type {};
101
107 template<class... T>
108 struct IsTypeList<TypeList<T...> > : std::true_type {};
109
110
111
120 template<class T>
121 struct IsEmptyTypeList : std::is_same<T, TypeList<> > {};
122
123
124
125 template<class T>
126 struct TypeListSize {};
127
136 template<class... T>
137 struct TypeListSize<TypeList<T...>> : std::integral_constant<std::size_t, sizeof...(T)> {};
138
139
140
141 template<std::size_t i, class T>
142 struct TypeListElement {};
143
149 template<std::size_t i, class... T>
150 struct TypeListElement<i, TypeList<T...>>
151 {
157 using type = typename std::tuple_element<i, std::tuple<T...>>::type;
158
164 using Type = type;
165 };
166
170 template<std::size_t i, class T>
171 using TypeListEntry_t = typename TypeListElement<i, T>::type;
172
173 namespace Impl {
174
175 template<template<class...> class Target, class ToDoList, class... Processed>
176 struct UniqueTypesHelper;
177
178 template<template<class...> class Target, class... Processed>
179 struct UniqueTypesHelper<Target, TypeList<>, Processed...>
180 {
181 using type = Target<Processed...>;
182 };
183
184 template<template<class...> class Target, class T0, class... T, class... Processed>
185 struct UniqueTypesHelper<Target, TypeList<T0, T...>, Processed...>
186 {
187 using type = std::conditional_t<
188 std::disjunction<std::is_same<T0, Processed>...>::value,
189 typename UniqueTypesHelper<Target, TypeList<T...>, Processed...>::type,
190 typename UniqueTypesHelper<Target, TypeList<T...>, T0, Processed...>::type>;
191 };
192
193 // Helper for unpacking Dune::TypeList
194 template<template<class...> class Target, class TL>
195 struct UnpackTypeList;
196
197 template<template<class...> class Target, class... T>
198 struct UnpackTypeList<Target, Dune::TypeList<T...>>
199 {
200 using type = Target<T...>;
201 };
202
203 } // namespace Impl
204
209 template<template<class...> class Target, class TL>
210 using UnpackTypeList_t = typename Impl::UnpackTypeList<Target, TL>::type;
211
219 template<template<class...> class Target, class... T>
220 using UniqueTypes_t = typename Impl::UniqueTypesHelper<Target, TypeList<T...>>::type;
221
227 template<class NonUniqueTypeList>
228 using UniqueTypeList_t = typename Impl::UniqueTypesHelper<TypeList, NonUniqueTypeList>::type;
229
235 template<class... T>
236 constexpr auto uniqueTypeList(TypeList<T...> list)
237 {
238 return typename Impl::UniqueTypesHelper<TypeList, TypeList<T...>>::type{};
239 }
240
241
242
243} // namespace Dune
244
245#endif // DUNE_COMMON_TYPELIST_HH
std::tuple< MetaType< T >... > TypeList
A simple type list.
Definition: typelist.hh:87
Dune namespace.
Definition: alignedallocator.hh:13
typename Impl::UnpackTypeList< Target, TL >::type UnpackTypeList_t
Unpack Dune::TypeList.
Definition: typelist.hh:210
constexpr auto uniqueTypeList(TypeList< T... > list)
Remove duplicates from a Dune::TypeList.
Definition: typelist.hh:236
typename Impl::UniqueTypesHelper< Target, TypeList< T... > >::type UniqueTypes_t
Remove duplicates from a list of types.
Definition: typelist.hh:220
typename Impl::UniqueTypesHelper< TypeList, NonUniqueTypeList >::type UniqueTypeList_t
Remove duplicates from a Dune::TypeList.
Definition: typelist.hh:228
typename TypeListElement< i, T >::type TypeListEntry_t
Shortcut for TypeListElement<i, T>::type;.
Definition: typelist.hh:171
Check if given type is an empty TypeList.
Definition: typelist.hh:121
Check if given type is a TypeList.
Definition: typelist.hh:100
A type that refers to another type.
Definition: typelist.hh:33
T type
The referred-to type.
Definition: typelist.hh:35
typename std::tuple_element< i, std::tuple< T... > >::type type
Export type of i-th element in TypeList.
Definition: typelist.hh:157
type Type
Export type of i-th element in TypeList.
Definition: typelist.hh:164
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 27, 23:30, 2024)