Skip to content
Snippets Groups Projects
Commit bdbcc7dc authored by Carsten Gräser's avatar Carsten Gräser
Browse files

Merge branch 'feature/typelist' into 'master'

Feature/typelist

This adds `template<class...T> struct TypeList {};`
together with some utilities. It's e.g. used in the
concept checking facility that I'll add soon.

Besides this it can be used to 'store' an argument pack and access
its members. In contrast to a `std::tuple<T...>` which is
a container of objects of types `T...` a `TypeList<T...>`
only captures the types themselves . Hence one can easily
create TypeList objects and use them to pass types around
or, e.g., in overload resolution where they can be used for
tag-dispatch.

Notice that adding a template `packer<T...>` doing exactly
the same has been proposed for the standard in [N4115][].
But in my opinion TypeList is a more instructive name.

[N4115]: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4115.html

See merge request !7
parents 2734ae24 22c410ca
No related branches found
No related tags found
No related merge requests found
......@@ -89,6 +89,7 @@ install(FILES
timer.hh
tuples.hh
tupleutility.hh
typelist.hh
typetraits.hh
unused.hh
version.hh
......
......@@ -83,6 +83,7 @@ commoninclude_HEADERS = \
timer.hh \
tuples.hh \
tupleutility.hh \
typelist.hh \
typetraits.hh \
unused.hh \
version.hh \
......
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_COMMON_TYPELIST_HH
#define DUNE_COMMON_TYPELIST_HH
#include <type_traits>
#include <tuple>
namespace Dune {
/**
* \brief A simple type list
*
* \ingroup TypeUtilities
*
* 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
*/
template<class... T>
struct TypeList
{};
/**
* \brief Check if given type is a TypeList
*
* \ingroup TypeUtilities
*
* The result of the check is encoded in the
* base class of type std::integral_constant<bool, result>.
*/
template<class T>
struct IsTypeList : std::false_type {};
/**
* \copydoc IsTypeList
*
* \ingroup TypeUtilities
*/
template<class... T>
struct IsTypeList<TypeList<T...> > : std::true_type {};
/**
* \brief Check if given type is an empty TypeList
*
* \ingroup TypeUtilities
*
* The result of the check is encoded in the
* base class of type std::integral_constant<bool, result>.
*/
template<class T>
struct IsEmptyTypeList : std::integral_constant<bool, IsTypeList<T>() and std::is_same<T, TypeList<> >() > {};
template<class T>
struct TypeListSize {};
/**
* \brief Get size of TypeList
*
* \ingroup TypeUtilities
*
* The result of is encoded in the base class of
* type std::integral_constant<std::size_t, result>.
*/
template<class... T>
struct TypeListSize<TypeList<T...>> : std::integral_constant<std::size_t, sizeof...(T)> {};
template<std::size_t i, class T>
struct TypeListElement {};
/**
* \brief Get element of TypeList
*
* \ingroup TypeUtilities
*/
template<std::size_t i, class... T>
struct TypeListElement<i, TypeList<T...>>
{
/**
* \brief Export type of i-th element in TypeList
*
* \todo Implement without using std::tuple.
*/
using type = typename std::tuple_element<i, std::tuple<T...>>::type;
/**
* \brief Export type of i-th element in TypeList
*
* \todo Implement without using std::tuple.
*/
using Type = type;
};
/**
* \brief Shortcut for TypeListElement<i, T>::type;
*/
template<std::size_t i, class T>
using TypeListEntry_t = typename TypeListElement<i, T>::type;
} // namespace Dune
#endif // DUNE_COMMON_TYPELIST_HH
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment