Loading...
Searching...
No Matches
typetraits.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: LGPL-3.0-or-later OR LicenseRef-GPL-2.0-only-with-PDELab-exception
#ifndef DUNE_TYPETREE_TYPETRAITS_HH
#define DUNE_TYPETREE_TYPETRAITS_HH
#include <type_traits>
#include <dune/common/typetraits.hh>
#include <dune/typetree/treepath.hh>
#include <dune/typetree/nodeinterface.hh>
namespace Dune {
// Provide some more C++11 TMP helpers.
// These should be upstreamed to dune-common ASAP.
template<typename... T>
struct first_type;
template<typename T0, typename... T>
struct first_type<T0,T...>
{
typedef T0 type;
};
namespace TypeTree {
template<typename T>
struct has_node_tag
{
struct yes { char dummy[1]; };
struct no { char dummy[2]; };
template<typename X>
static yes test(NodeTag<X> *);
template<typename X>
static no test(...);
constexpr static bool value = sizeof(test<T>(0)) == sizeof(yes);
};
template<typename T, typename V>
struct has_node_tag_value
{
template<int N>
struct maybe { char dummy[N+1]; };
struct yes { char dummy[2]; };
struct no { char dummy[1]; };
template<typename X>
static maybe<std::is_base_of<V, NodeTag<X>>::value>
test(NodeTag<X> * a);
template<typename X>
static no test(...);
constexpr static bool value = sizeof(test<T>(0)) == sizeof(yes);
};
template<typename T>
struct has_implementation_tag
{
struct yes { char dummy[1]; };
struct no { char dummy[2]; };
template<typename X>
static yes test(ImplementationTag<X> *);
template<typename X>
static no test(...);
constexpr static bool value = sizeof(test<T>(0)) == sizeof(yes);
};
template<typename T, typename V>
struct has_implementation_tag_value
{
template<int N>
struct maybe { char dummy[N+1]; };
struct yes { char dummy[2]; };
struct no { char dummy[1]; };
template<typename X>
static maybe<std::is_base_of<V, ImplementationTag<X>>::value>
test(ImplementationTag<X> * a);
template<typename X>
static no test(...);
constexpr static bool value = sizeof(test<T>(0)) == sizeof(yes);
};
template<typename>
struct AlwaysVoid
{
typedef void type;
};
template<typename T>
T* declptr();
// Support for lazy evaluation of meta functions. This is required when doing
// nested tag dispatch without C++11-style typedefs (based on using syntax).
// The standard struct-based meta functions cause premature evaluation in a
// context that is not SFINAE-compatible. We thus have to return the meta function
// without evaluating it, placing that burden on the caller. On the other hand,
// the lookup will often directly be the target type, so here is some helper code
// to automatically do the additional evaluation if necessary.
// Too bad that the new syntax is GCC 4.6+...
struct meta_function {};
template<typename F>
struct lazy_evaluate
{
typedef typename F::type type;
};
template<typename F>
struct lazy_identity
{
typedef F type;
};
template<typename F>
struct evaluate_if_meta_function
{
typedef typename std::conditional<
std::is_base_of<meta_function,F>::value,
lazy_evaluate<F>,
lazy_identity<F>
>::type::type type;
};
namespace impl {
// Check if type is a or is derived from one of the tree path types
// Default overload for types not representing a tree path
constexpr auto isTreePath(void*)
-> std::false_type
{
return std::false_type();
}
// Overload for instances of HybridTreePath<...>
template<class... I>
constexpr auto isTreePath(const HybridTreePath<I...>*)
-> std::true_type
{
return std::true_type();
}
}
template<class T>
struct IsTreePath :
public decltype(impl::isTreePath((typename std::decay<T>::type*)(nullptr)))
{};
template<class T>
constexpr auto isTreePath(const T&)
-> IsTreePath<T>
{
return IsTreePath<T>();
}
} // end namespace TypeTree
} // end namespace Dune
#endif // DUNE_TYPETREE_TYPETRAITS_HH
treepath.hh
nodeinterface.hh
Dune::TypeTree::ImplementationTag
typename std::decay_t< T >::ImplementationTag ImplementationTag
Returns the implementation tag of the given Node.
Definition nodeinterface.hh:74
Dune::TypeTree::NodeTag
typename std::decay_t< Node >::NodeTag NodeTag
Returns the node tag of the given Node.
Definition nodeinterface.hh:70
Dune::TypeTree::HybridTreePath
Dune::HybridMultiIndex< T... > HybridTreePath
A type for representing tree paths that supports both compile time and run time indices.
Definition treepath.hh:85
Dune
Definition accumulate_static.hh:17
Dune::TypeTree
Definition accumulate_static.hh:18
Dune::TypeTree::isTreePath
constexpr auto isTreePath(const T &) -> IsTreePath< T >
Check if given object represents a tree path.
Definition typetraits.hh:193
Dune::TypeTree::declptr
T * declptr()
Helper function for generating a pointer to a value of type T in an unevaluated operand setting.
Dune::TypeTree::impl
Definition typetraits.hh:150
Dune::TypeTree::impl::isTreePath
constexpr auto isTreePath(void *) -> std::false_type
Definition typetraits.hh:155
Dune::first_type
Definition typetraits.hh:21
Dune::first_type< T0, T... >::type
T0 type
Definition typetraits.hh:26
Dune::TypeTree::has_node_tag
Definition typetraits.hh:33
Dune::TypeTree::has_node_tag::value
static constexpr bool value
True if class T defines a NodeTag.
Definition typetraits.hh:43
Dune::TypeTree::has_node_tag::test
static yes test(NodeTag< X > *)
Dune::TypeTree::has_node_tag::test
static no test(...)
Dune::TypeTree::has_node_tag::yes
Definition typetraits.hh:34
Dune::TypeTree::has_node_tag::yes::dummy
char dummy[1]
Definition typetraits.hh:34
Dune::TypeTree::has_node_tag::no
Definition typetraits.hh:35
Dune::TypeTree::has_node_tag::no::dummy
char dummy[2]
Definition typetraits.hh:35
Dune::TypeTree::has_node_tag_value
Definition typetraits.hh:48
Dune::TypeTree::has_node_tag_value::test
static maybe< std::is_base_of< V, NodeTag< X > >::value > test(NodeTag< X > *a)
Dune::TypeTree::has_node_tag_value::value
static constexpr bool value
True if class T defines a NodeTag of type V.
Definition typetraits.hh:61
Dune::TypeTree::has_node_tag_value::test
static no test(...)
Dune::TypeTree::has_node_tag_value::maybe
Definition typetraits.hh:50
Dune::TypeTree::has_node_tag_value::maybe::dummy
char dummy[N+1]
Definition typetraits.hh:50
Dune::TypeTree::has_node_tag_value::yes
Definition typetraits.hh:51
Dune::TypeTree::has_node_tag_value::yes::dummy
char dummy[2]
Definition typetraits.hh:51
Dune::TypeTree::has_node_tag_value::no
Definition typetraits.hh:52
Dune::TypeTree::has_node_tag_value::no::dummy
char dummy[1]
Definition typetraits.hh:52
Dune::TypeTree::has_implementation_tag
Definition typetraits.hh:66
Dune::TypeTree::has_implementation_tag::test
static yes test(ImplementationTag< X > *)
Dune::TypeTree::has_implementation_tag::test
static no test(...)
Dune::TypeTree::has_implementation_tag::value
static constexpr bool value
True if class T defines an ImplementationTag.
Definition typetraits.hh:76
Dune::TypeTree::has_implementation_tag::yes
Definition typetraits.hh:67
Dune::TypeTree::has_implementation_tag::yes::dummy
char dummy[1]
Definition typetraits.hh:67
Dune::TypeTree::has_implementation_tag::no
Definition typetraits.hh:68
Dune::TypeTree::has_implementation_tag::no::dummy
char dummy[2]
Definition typetraits.hh:68
Dune::TypeTree::has_implementation_tag_value
Definition typetraits.hh:81
Dune::TypeTree::has_implementation_tag_value::test
static maybe< std::is_base_of< V, ImplementationTag< X > >::value > test(ImplementationTag< X > *a)
Dune::TypeTree::has_implementation_tag_value::test
static no test(...)
Dune::TypeTree::has_implementation_tag_value::value
static constexpr bool value
True if class T defines an ImplementationTag of type V.
Definition typetraits.hh:94
Dune::TypeTree::has_implementation_tag_value::maybe
Definition typetraits.hh:83
Dune::TypeTree::has_implementation_tag_value::maybe::dummy
char dummy[N+1]
Definition typetraits.hh:83
Dune::TypeTree::has_implementation_tag_value::yes
Definition typetraits.hh:84
Dune::TypeTree::has_implementation_tag_value::yes::dummy
char dummy[2]
Definition typetraits.hh:84
Dune::TypeTree::has_implementation_tag_value::no
Definition typetraits.hh:85
Dune::TypeTree::has_implementation_tag_value::no::dummy
char dummy[1]
Definition typetraits.hh:85
Dune::TypeTree::AlwaysVoid
Definition typetraits.hh:99
Dune::TypeTree::AlwaysVoid::type
void type
Definition typetraits.hh:100
Dune::TypeTree::meta_function
Marker tag declaring a meta function.
Definition typetraits.hh:123
Dune::TypeTree::lazy_evaluate
Helper meta function to delay evaluation of F.
Definition typetraits.hh:128
Dune::TypeTree::lazy_evaluate::type
F::type type
Definition typetraits.hh:129
Dune::TypeTree::lazy_identity
Identity function.
Definition typetraits.hh:135
Dune::TypeTree::lazy_identity::type
F type
Definition typetraits.hh:136
Dune::TypeTree::evaluate_if_meta_function
Meta function that evaluates its argument iff it inherits from meta_function.
Definition typetraits.hh:142
Dune::TypeTree::evaluate_if_meta_function::type
std::conditional< std::is_base_of< meta_function, F >::value, lazy_evaluate< F >, lazy_identity< F > >::type::type type
Definition typetraits.hh:147
Dune::TypeTree::IsTreePath
Check if type represents a tree path.
Definition typetraits.hh:184