Dune Core Modules (2.5.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_COMMON_STD_TYPE_TRAITS_HH
4#define DUNE_COMMON_STD_TYPE_TRAITS_HH
5
6#include <type_traits>
9
10namespace Dune
11{
12
13namespace 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
88 using std::experimental::bool_constant;
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>
112 std::true_type is_callable_helper(PriorityTag<2>)
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>
122 std::true_type is_callable_helper(PriorityTag<1>)
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>
129 std::false_type is_callable_helper(PriorityTag<0>)
130 { return {}; }
131 }
132
148 template <class D, class R= void>
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
Dune namespace.
Definition: alignment.hh:11
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:60
Traits class to check if function is callable.
Definition: type_traits.hh:149
template mapping a type to std::false_type
Definition: type_traits.hh:63
template mapping a type to std::true_type
Definition: type_traits.hh:79
Traits for type conversions and type information.
Utilities for type computations, constraining overloads, ...
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)