Dune Core Modules (2.9.0)

type_traits.hh
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_FUNCTIONS_COMMON_TYPE_TRAITS_HH
4 #define DUNE_FUNCTIONS_COMMON_TYPE_TRAITS_HH
5 
6 #include <type_traits>
7 
9 
10 namespace Dune {
11 namespace Functions {
12 
13 
24 template<class T, class... Args>
25 using enableIfConstructible = typename std::enable_if<
26  std::is_constructible<T, Args...>::value, int>::type;
27 
28 
29 
30 namespace Imp {
31 
32  // As a last resort try if there's a static constexpr size()
33  template<class T>
34  constexpr auto staticSize(const T*, const PriorityTag<0>&)
35  -> decltype(std::integral_constant<std::size_t,T::size()>())
36  {
37  return {};
38  }
39 
40  // Try if class has constexpr default constructor and size method
41  template<class T>
42  constexpr auto staticSize(const T*, const PriorityTag<1>&)
43  -> decltype(std::integral_constant<std::size_t,T().size()>())
44  {
45  return {};
46  }
47 
48  // Try if tuple_size is implemented for class
49  template<class T>
50  constexpr auto staticSize(const T*, const PriorityTag<2>&)
51  -> decltype(std::integral_constant<std::size_t,std::tuple_size<T>::value>())
52  {
53  return {};
54  }
55 
56  template<class T>
57  constexpr std::false_type hasStaticSize(const T* t, const PriorityTag<0>& p)
58  {
59  return {};
60  }
61 
62  template<class T>
63  constexpr auto hasStaticSize(const T* t, const PriorityTag<1>& p)
64  -> decltype(staticSize(t ,PriorityTag<42>()), std::true_type())
65  {
66  return {};
67  }
68 
69 }
70 
71 
72 
80 template<class T>
81 struct HasStaticSize :
82  public decltype(Imp::hasStaticSize((typename std::decay<T>::type*)(nullptr), PriorityTag<42>()))
83 {};
84 
85 
86 
94 template<class T>
95 struct StaticSize :
96  public decltype(Imp::staticSize((typename std::decay<T>::type*)(nullptr), PriorityTag<42>()))
97 {};
98 
99 
100 
101 }} // namespace Dune::Functions
102 
103 #endif // DUNE_FUNCTIONS_COMMON_TYPE_TRAITS_HH
typename std::enable_if< std::is_constructible< T, Args... >::value, int >::type enableIfConstructible
Helper to constrain forwarding constructors.
Definition: type_traits.hh:26
Dune namespace.
Definition: alignedallocator.hh:13
Check if type is a statically sized container.
Definition: type_traits.hh:83
Obtain size of statically sized container.
Definition: type_traits.hh:97
Helper class for tagging priorities.
Definition: typeutilities.hh:87
Helper class for tagging priorities.
Definition: typeutilities.hh:73
Utilities for type computations, constraining overloads, ...
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 16, 22:29, 2024)