2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP_EXPERIMENTAL_TYPE_TRAITS
11 #define _LIBCPP_EXPERIMENTAL_TYPE_TRAITS
14 experimental/type_traits synopsis
17 #include <type_traits>
20 namespace experimental {
21 inline namespace fundamentals_v1 {
23 // 3.3.2, Other type transformations
24 template <class> class invocation_type; // not defined
25 template <class F, class... ArgTypes> class invocation_type<F(ArgTypes...)>;
26 template <class> class raw_invocation_type; // not defined
27 template <class F, class... ArgTypes> class raw_invocation_type<F(ArgTypes...)>;
30 using invocation_type_t = typename invocation_type<T>::type;
32 using raw_invocation_type_t = typename raw_invocation_type<T>::type;
34 // 3.3.4, Detection idiom
35 template <class...> using void_t = void;
40 nonesuch(nonesuch const&) = delete;
41 void operator=(nonesuch const&) = delete;
44 template <template<class...> class Op, class... Args>
45 using is_detected = see below;
46 template <template<class...> class Op, class... Args>
47 constexpr bool is_detected_v = is_detected<Op, Args...>::value;
48 template <template<class...> class Op, class... Args>
49 using detected_t = see below;
50 template <class Default, template<class...> class Op, class... Args>
51 using detected_or = see below;
52 template <class Default, template<class...> class Op, class... Args>
53 using detected_or_t = typename detected_or<Default, Op, Args...>::type;
54 template <class Expected, template<class...> class Op, class... Args>
55 using is_detected_exact = is_same<Expected, detected_t<Op, Args...>>;
56 template <class Expected, template<class...> class Op, class... Args>
57 constexpr bool is_detected_exact_v
58 = is_detected_exact<Expected, Op, Args...>::value;
59 template <class To, template<class...> class Op, class... Args>
60 using is_detected_convertible = is_convertible<detected_t<Op, Args...>, To>;
61 template <class To, template<class...> class Op, class... Args>
62 constexpr bool is_detected_convertible_v
63 = is_detected_convertible<To, Op, Args...>::value;
65 } // namespace fundamentals_v1
66 } // namespace experimental
71 #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
72 # include <__cxx03/experimental/type_traits>
76 # if _LIBCPP_STD_VER >= 14
78 # include <initializer_list>
79 # include <type_traits>
81 # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
82 # pragma GCC system_header
85 _LIBCPP_BEGIN_NAMESPACE_LFTS
87 // 3.3.2, Other type transformations
90 class _LIBCPP_TEMPLATE_VIS raw_invocation_type;
92 template <class _Fn, class ..._Args>
93 class _LIBCPP_TEMPLATE_VIS raw_invocation_type<_Fn(_Args...)>;
96 class _LIBCPP_TEMPLATE_VIS invokation_type;
98 template <class _Fn, class ..._Args>
99 class _LIBCPP_TEMPLATE_VIS invokation_type<_Fn(_Args...)>;
102 using invokation_type_t = typename invokation_type<_Tp>::type;
105 using raw_invocation_type_t = typename raw_invocation_type<_Tp>::type;
108 // 3.3.4, Detection idiom
112 struct nonesuch : private __nat { // make nonesuch "not an aggregate"
113 ~nonesuch() = delete;
114 nonesuch(nonesuch const&) = delete;
115 void operator=(nonesuch const&) = delete;
118 template <class _Default, class _AlwaysVoid, template <class...> class _Op, class... _Args>
120 using value_t = false_type;
121 using type = _Default;
124 template <class _Default, template <class...> class _Op, class... _Args>
125 struct _DETECTOR<_Default, void_t<_Op<_Args...>>, _Op, _Args...> {
126 using value_t = true_type;
127 using type = _Op<_Args...>;
130 template <template <class...> class _Op, class... _Args>
131 using is_detected = typename _DETECTOR<nonesuch, void, _Op, _Args...>::value_t;
132 template <template <class...> class _Op, class... _Args>
133 using detected_t = typename _DETECTOR<nonesuch, void, _Op, _Args...>::type;
134 template <template <class...> class _Op, class... _Args>
135 constexpr bool is_detected_v = is_detected<_Op, _Args...>::value;
137 template <class _Default, template <class...> class _Op, class... _Args>
138 using detected_or = _DETECTOR<_Default, void, _Op, _Args...>;
139 template <class _Default, template <class...> class _Op, class... _Args>
140 using detected_or_t = typename detected_or<_Default, _Op, _Args...>::type;
142 template <class _Expected, template <class...> class _Op, class... _Args>
143 using is_detected_exact = is_same<_Expected, detected_t<_Op, _Args...>>;
144 template <class _Expected, template <class...> class _Op, class... _Args>
145 constexpr bool is_detected_exact_v = is_detected_exact<_Expected, _Op, _Args...>::value;
147 template <class _To, template <class...> class _Op, class... _Args>
148 using is_detected_convertible = is_convertible<detected_t<_Op, _Args...>, _To>;
149 template <class _To, template <class...> class _Op, class... _Args>
150 constexpr bool is_detected_convertible_v = is_detected_convertible<_To, _Op, _Args...>::value;
152 _LIBCPP_END_NAMESPACE_LFTS
154 # if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
158 # endif /* _LIBCPP_STD_VER >= 14 */
159 #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
161 #endif /* _LIBCPP_EXPERIMENTAL_TYPE_TRAITS */