dune-typetree  2.3.1
typetraits.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 
4 #ifndef DUNE_TYPETREE_TYPETRAITS_HH
5 #define DUNE_TYPETREE_TYPETRAITS_HH
6 
7 #include <dune/common/typetraits.hh>
8 
9 namespace Dune {
10 
11  // Provide some more C++11 TMP helpers.
12  // These should be upstreamed to dune-common ASAP.
13 
14 #if defined HAVE_TYPE_TRAITS
15 
16  // Tests whether the first template argument is a base class of the second one.
17  using std::is_base_of;
18 
19 #elif defined HAVE_TR1_TYPE_TRAITS
20 
21  // This is already in TR1
22  using std::tr1::is_base_of;
23 
24 #else
25 
26  // Every compiler we currently support should have TR1.
27 #error Your compiler supports neither C++11 nor TR1!
28 #error TypeTree requires at least TR1 support in your compiler to work, bailing out...
29 
30 #endif
31 
32  namespace TypeTree {
33 
34  template<typename>
35  struct AlwaysVoid
36  {
37  typedef void type;
38  };
39 
40 #ifndef DOXYGEN
41 
42 // Make sure we have decltype or a compatible fall back
43 
44 #if HAVE_STD_DECLTYPE
45 #define DUNE_DECLTYPE decltype
46 #elif HAVE_GCC___TYPEOF__
47 #define DUNE_DECLTYPE __typeof__
48 #else
49 #error The TypeTree library requires support for
50 #error C++11 decltype or a compatible fallback in your compiler.
51 #error Neither of those was found, aborting!!!!
52 #endif
53 
54 #endif // DOXYGEN
55 
56 
58  template<typename T>
59  T* declptr();
60 
61 
62  // Support for lazy evaluation of meta functions. This is required when doing
63  // nested tag dispatch without C++11-style typedefs (based on using syntax).
64  // The standard struct-based meta functions cause premature evaluation in a
65  // context that is not SFINAE-compatible. We thus have to return the meta function
66  // without evaluating it, placing that burden on the caller. On the other hand,
67  // the lookup will often directly the target type, so here is some helper code
68  // to automatically do the additional evaluation if necessary.
69  // Too bad that the new syntax is GCC 4.6+...
70 
71 
73 
76  struct meta_function {};
77 
79  template<typename F>
81  {
82  typedef typename F::type type;
83  };
84 
86  template<typename F>
88  {
89  typedef F type;
90  };
91 
93  template<typename F>
95  {
96  typedef typename conditional<
100  >::type::type type;
101  };
102 
103  } // end namespace TypeTree
104 } // end namespace Dune
105 
106 #endif // DUNE_TYPETREE_TYPETRAITS_HH
F::type type
Definition: typetraits.hh:82
Marker tag declaring a meta function.
Definition: typetraits.hh:76
Meta function that evaluates its argument iff it inherits from meta_function.
Definition: typetraits.hh:94
Identity function.
Definition: typetraits.hh:87
conditional< is_base_of< meta_function, F >::value, lazy_evaluate< F >, lazy_identity< F > >::type::type type
Definition: typetraits.hh:100
Helper meta function to delay evaluation of F.
Definition: typetraits.hh:80
F type
Definition: typetraits.hh:89
void type
Definition: typetraits.hh:37
static const std::size_t value
Definition: compositenode.hh:38
T * declptr()
Helper function for generating a pointer to a value of type T in an unevaluated operand setting...
Definition: typetraits.hh:35