DUNE PDELab (git)

Type Utilities

Type traits, overload helpers, and other utilities for type computations. More...

Classes

struct  Dune::MetaType< T >
 A type that refers to another type. More...
 
struct  Dune::IsTypeList< T >
 Check if given type is a TypeList. More...
 
struct  Dune::IsTypeList< TypeList< T... > >
 Check if given type is a TypeList. More...
 
struct  Dune::IsEmptyTypeList< T >
 Check if given type is an empty TypeList. More...
 
struct  Dune::TypeListSize< TypeList< T... > >
 Get size of TypeList. More...
 
struct  Dune::TypeListElement< i, TypeList< T... > >
 Get element of TypeList. More...
 
struct  Dune::PriorityTag< priority >
 Helper class for tagging priorities. More...
 
struct  Dune::PriorityTag< 0 >
 Helper class for tagging priorities. More...
 

Typedefs

template<class... T>
using Dune::TypeList = std::tuple< MetaType< T >... >
 A simple type list. More...
 
template<class This , class... T>
using Dune::disableCopyMove = std::enable_if_t< not Impl::disableCopyMoveHelper< This, T... >::value, int >
 Helper to disable constructor as copy and move constructor. More...
 

Detailed Description

Type traits, overload helpers, and other utilities for type computations.

Typedef Documentation

◆ disableCopyMove

template<class This , class... T>
using Dune::disableCopyMove = typedef std::enable_if_t< not Impl::disableCopyMoveHelper<This, T...>::value, int>

Helper to disable constructor as copy and move constructor.

Helper typedef to remove constructor with forwarding reference from overload set for copy and move constructor or assignment.

◆ TypeList

template<class... T>
using Dune::TypeList = typedef std::tuple<MetaType<T>...>

A simple type list.

The purpose of this is to encapsulate a list of types. This allows, e.g., to pack an argument-pack into one type. In contrast to a std::tuple a TypeList can be created without creating any object of the stored types.

This can, e.g., be used for overload resolution with tag-dispatch where TypeList is used as tag. In combination with PriorityTag this allows to emulate partial specialization of function templates in a sane way, i.e., without the hassle of classic specialization of function templates

A TypeList<T...> can be iterated over using Hybrid::forEach(). For the purpose of iterating with Hybrid::forEach(), the members of TypeList<T...>{} are MetaType<T>{}.... This allows iteration over incomplete and non-constructible types, since no attempt is made to create objects of those types:

using namespace Hybrid;
struct NonConstructible { NonConstructible() = delete; };
forEach(TypeList<void, NonConstructible, int>{}, [] (auto metaType) {
std::cout << className<typename decltype(metaType)::type>()
<< std::endl;
});
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:256

It is also possible to iterate over complete-but-non-instantiable types, e.g. tuple<void>. But to do so you need to suppress ADL in the invocation of forEach(), since ADL would try to instantiate complete types in the template argument list of TypeList in order to find the associated namespaces. To suppress ADL you can either use a qualified lookup:

Hybrid::forEach(TypeList<std::tuple<void> >{},
[] (auto metaType) { ... });
});
std::tuple< MetaType< T >... > TypeList
A simple type list.
Definition: typelist.hh:87

or you can enclose the name forEach in parentheses:

using namespace Hybrid;
(forEach)(TypeList<std::tuple<void> >{}, [] (auto metaType) { ... });
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)