Loading...
Searching...
No Matches
typelist.hh
Go to the documentation of this file.
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_COMMON_TYPELIST_HH
#define DUNE_COMMON_TYPELIST_HH
#include <type_traits>
#include <tuple>
#include <utility>
namespace Dune {
template<class T>
struct MetaType {
using type = T;
};
template<class... T>
using TypeList = std::tuple<MetaType<T>...>;
template<class T>
struct IsTypeList : std::false_type {};
template<class... T>
struct IsTypeList<TypeList<T...> > : std::true_type {};
template<class T>
struct IsEmptyTypeList : std::is_same<T, TypeList<> > {};
template<class T>
struct TypeListSize {};
template<class... T>
struct TypeListSize<TypeList<T...>> : std::integral_constant<std::size_t, sizeof...(T)> {};
template<std::size_t i, class T>
struct TypeListElement {};
template<std::size_t i, class... T>
struct TypeListElement<i, TypeList<T...>>
{
using type = typename std::tuple_element<i, std::tuple<T...>>::type;
using Type = type;
};
template<std::size_t i, class T>
using TypeListEntry_t = typename TypeListElement<i, T>::type;
namespace Impl {
template<template<class...> class Target, class ToDoList, class... Processed>
struct UniqueTypesHelper;
template<template<class...> class Target, class... Processed>
struct UniqueTypesHelper<Target, TypeList<>, Processed...>
{
using type = Target<Processed...>;
};
template<template<class...> class Target, class T0, class... T, class... Processed>
struct UniqueTypesHelper<Target, TypeList<T0, T...>, Processed...>
{
using type = std::conditional_t<
std::disjunction<std::is_same<T0, Processed>...>::value,
typename UniqueTypesHelper<Target, TypeList<T...>, Processed...>::type,
typename UniqueTypesHelper<Target, TypeList<T...>, T0, Processed...>::type>;
};
// Helper for unpacking Dune::TypeList
template<template<class...> class Target, class TL>
struct UnpackTypeList;
template<template<class...> class Target, class... T>
struct UnpackTypeList<Target, Dune::TypeList<T...>>
{
using type = Target<T...>;
};
} // namespace Impl
template<template<class...> class Target, class TL>
using UnpackTypeList_t = typename Impl::UnpackTypeList<Target, TL>::type;
template<template<class...> class Target, class... T>
using UniqueTypes_t = typename Impl::UniqueTypesHelper<Target, TypeList<T...>>::type;
template<class NonUniqueTypeList>
using UniqueTypeList_t = typename Impl::UniqueTypesHelper<TypeList, NonUniqueTypeList>::type;
template<class... T>
constexpr auto uniqueTypeList(TypeList<T...> /*list*/)
{
return typename Impl::UniqueTypesHelper<TypeList, TypeList<T...>>::type{};
}
} // namespace Dune
#endif // DUNE_COMMON_TYPELIST_HH
Dune::TypeList
std::tuple< MetaType< T >... > TypeList
A simple type list.
Definition typelist.hh:87
Dune
Dune namespace
Definition alignedallocator.hh:13
Dune::uniqueTypeList
constexpr auto uniqueTypeList(TypeList< T... >)
Remove duplicates from a Dune::TypeList.
Definition typelist.hh:236
Dune::UniqueTypeList_t
typename Impl::UniqueTypesHelper< TypeList, NonUniqueTypeList >::type UniqueTypeList_t
Remove duplicates from a Dune::TypeList.
Definition typelist.hh:228
Dune::UniqueTypes_t
typename Impl::UniqueTypesHelper< Target, TypeList< T... > >::type UniqueTypes_t
Remove duplicates from a list of types.
Definition typelist.hh:220
Dune::UnpackTypeList_t
typename Impl::UnpackTypeList< Target, TL >::type UnpackTypeList_t
Unpack Dune::TypeList.
Definition typelist.hh:210
Dune::TypeListEntry_t
typename TypeListElement< i, T >::type TypeListEntry_t
Shortcut for TypeListElement<i, T>::type;.
Definition typelist.hh:171
Dune::type
Dune::MetaType
A type that refers to another type.
Definition typelist.hh:33
Dune::MetaType::type
T type
The referred-to type.
Definition typelist.hh:35
Dune::IsTypeList
Check if given type is a TypeList.
Definition typelist.hh:100
Dune::IsEmptyTypeList
Check if given type is an empty TypeList.
Definition typelist.hh:121
Dune::TypeListSize
Definition typelist.hh:126
Dune::TypeListElement
Definition typelist.hh:142
Dune::TypeListElement< i, TypeList< T... > >::type
typename std::tuple_element< i, std::tuple< T... > >::type type
Export type of i-th element in TypeList.
Definition typelist.hh:157
Dune::TypeListElement< i, TypeList< T... > >::Type
type Type
Export type of i-th element in TypeList.
Definition typelist.hh:164