dune-common  2.5.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
type_traits.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 #ifndef DUNE_COMMON_STD_TYPE_TRAITS_HH
4 #define DUNE_COMMON_STD_TYPE_TRAITS_HH
5 
6 #include <type_traits>
9 
10 namespace Dune
11 {
12 
13 namespace Std
14 {
15 
16  // to_false_type
17  // -------------
18 
62  template< typename T >
63  struct to_false_type : public std::false_type {};
64 
65 
66 
67  // to_true_type
68  // ------------
69 
78  template< typename T >
79  struct to_true_type : public std::true_type {};
80 
81 
82 #if __cpp_lib_bool_constant
83 
84  using std::bool_constant;
85 
86 #elif __cpp_lib_experimental_bool_constant
87 
89 
90 #else
91 
97  template <bool value>
98  using bool_constant = std::integral_constant<bool, value>;
99 
100 #endif
101 
102 
103  namespace Imp {
104 
105  // If R is void we only need to check if F can be called
106  // with given Args... list. If this is not possible
107  // result_of_t is not defined and this overload is disabled.
108  template<class R, class F, class... Args,
109  std::enable_if_t<
110  std::is_same<void_t<std::result_of_t<F(Args...)>>, R>::value
111  , int> = 0>
113  { return {}; }
114 
115  // Check if result of F(Args...) can be converted to R.
116  // If F cannot even be called with given Args... then
117  // result_of_t is not defined and this overload is disabled.
118  template<class R, class F, class... Args,
119  std::enable_if_t<
120  std::is_convertible<std::result_of_t<F(Args...)>, R>::value
121  , int> = 0>
123  { return {}; }
124 
125  // If none of the above matches, F can either not be called
126  // with given Args..., or the result cannot be converted to
127  // void, or R is not void.
128  template<class R, class F, class... Args>
130  { return {}; }
131  }
132 
148  template <class D, class R= void>
149  struct is_callable;
150 
166  template <class F, class... Args, class R>
167  struct is_callable< F(Args...), R> :
168  decltype(Imp::is_callable_helper<R, F, Args...>(PriorityTag<42>()))
169  {};
170 
171 
172 
173 
174 
175 
176 
177 
178 } // namespace Std
179 
180 } // namespace Dune
181 
182 #endif // #ifndef DUNE_COMMON_STD_TYPE_TRAITS_HH
Helper class for tagging priorities.
Definition: typeutilities.hh:59
template mapping a type to std::true_type
Definition: type_traits.hh:79
Traits class to check if function is callable.
Definition: type_traits.hh:149
Utilities for type computations, constraining overloads, ...
Traits for type conversions and type information.
typename detail::voider< Types...>::type void_t
Is void for all valid input types (see N3911). The workhorse for C++11 SFINAE-techniques.
Definition: typetraits.hh:35
Helper class for tagging priorities.
Definition: typeutilities.hh:71
std::integral_constant< bool, value > bool_constant
A template alias for std::integral_constant&lt;bool, value&gt;
Definition: type_traits.hh:98
std::true_type is_callable_helper(PriorityTag< 2 >)
Definition: type_traits.hh:112
template mapping a type to std::false_type
Definition: type_traits.hh:63