Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / include / __tuple / sfinae_helpers.h
blob2fffac9efda18b39d1015eb4af84e65acc9c5b4a
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___TUPLE_SFINAE_HELPERS_H
10 #define _LIBCPP___TUPLE_SFINAE_HELPERS_H
12 #include <__config>
13 #include <__fwd/tuple.h>
14 #include <__tuple/make_tuple_types.h>
15 #include <__tuple/tuple_element.h>
16 #include <__tuple/tuple_like_ext.h>
17 #include <__tuple/tuple_size.h>
18 #include <__tuple/tuple_types.h>
19 #include <__type_traits/enable_if.h>
20 #include <__type_traits/integral_constant.h>
21 #include <__type_traits/is_assignable.h>
22 #include <__type_traits/is_constructible.h>
23 #include <__type_traits/is_convertible.h>
24 #include <__type_traits/is_same.h>
25 #include <__type_traits/remove_cvref.h>
26 #include <__type_traits/remove_reference.h>
27 #include <cstddef>
29 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
30 # pragma GCC system_header
31 #endif
33 _LIBCPP_BEGIN_NAMESPACE_STD
35 #ifndef _LIBCPP_CXX03_LANG
37 template <bool ..._Preds>
38 struct __all_dummy;
40 template <bool ..._Pred>
41 struct __all : _IsSame<__all_dummy<_Pred...>, __all_dummy<((void)_Pred, true)...>> {};
43 struct __tuple_sfinae_base {
44 template <template <class, class...> class _Trait,
45 class ..._LArgs, class ..._RArgs>
46 static auto __do_test(__tuple_types<_LArgs...>, __tuple_types<_RArgs...>)
47 -> __all<__enable_if_t<_Trait<_LArgs, _RArgs>::value, bool>{true}...>;
48 template <template <class...> class>
49 static auto __do_test(...) -> false_type;
51 template <class _FromArgs, class _ToArgs>
52 using __constructible = decltype(__do_test<is_constructible>(_ToArgs{}, _FromArgs{}));
53 template <class _FromArgs, class _ToArgs>
54 using __convertible = decltype(__do_test<is_convertible>(_FromArgs{}, _ToArgs{}));
55 template <class _FromArgs, class _ToArgs>
56 using __assignable = decltype(__do_test<is_assignable>(_ToArgs{}, _FromArgs{}));
59 // __tuple_convertible
61 template <class _Tp, class _Up, bool = __tuple_like_ext<__libcpp_remove_reference_t<_Tp> >::value,
62 bool = __tuple_like_ext<_Up>::value>
63 struct __tuple_convertible
64 : public false_type {};
66 template <class _Tp, class _Up>
67 struct __tuple_convertible<_Tp, _Up, true, true>
68 : public __tuple_sfinae_base::__convertible<
69 typename __make_tuple_types<_Tp>::type
70 , typename __make_tuple_types<_Up>::type
72 {};
74 // __tuple_constructible
76 template <class _Tp, class _Up, bool = __tuple_like_ext<__libcpp_remove_reference_t<_Tp> >::value,
77 bool = __tuple_like_ext<_Up>::value>
78 struct __tuple_constructible
79 : public false_type {};
81 template <class _Tp, class _Up>
82 struct __tuple_constructible<_Tp, _Up, true, true>
83 : public __tuple_sfinae_base::__constructible<
84 typename __make_tuple_types<_Tp>::type
85 , typename __make_tuple_types<_Up>::type
87 {};
89 // __tuple_assignable
91 template <class _Tp, class _Up, bool = __tuple_like_ext<__libcpp_remove_reference_t<_Tp> >::value,
92 bool = __tuple_like_ext<_Up>::value>
93 struct __tuple_assignable
94 : public false_type {};
96 template <class _Tp, class _Up>
97 struct __tuple_assignable<_Tp, _Up, true, true>
98 : public __tuple_sfinae_base::__assignable<
99 typename __make_tuple_types<_Tp>::type
100 , typename __make_tuple_types<_Up&>::type
105 template <size_t _Ip, class ..._Tp>
106 struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, tuple<_Tp...> >
108 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type;
111 struct _LIBCPP_EXPORTED_FROM_ABI __check_tuple_constructor_fail {
113 static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_explicit_default() { return false; }
114 static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_implicit_default() { return false; }
115 template <class ...>
116 static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_explicit() { return false; }
117 template <class ...>
118 static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_implicit() { return false; }
119 template <class ...>
120 static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_assign() { return false; }
122 #endif // !defined(_LIBCPP_CXX03_LANG)
124 #if _LIBCPP_STD_VER >= 17
126 template <bool _CanCopy, bool _CanMove>
127 struct __sfinae_ctor_base {};
128 template <>
129 struct __sfinae_ctor_base<false, false> {
130 __sfinae_ctor_base() = default;
131 __sfinae_ctor_base(__sfinae_ctor_base const&) = delete;
132 __sfinae_ctor_base(__sfinae_ctor_base &&) = delete;
133 __sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default;
134 __sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default;
136 template <>
137 struct __sfinae_ctor_base<true, false> {
138 __sfinae_ctor_base() = default;
139 __sfinae_ctor_base(__sfinae_ctor_base const&) = default;
140 __sfinae_ctor_base(__sfinae_ctor_base &&) = delete;
141 __sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default;
142 __sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default;
144 template <>
145 struct __sfinae_ctor_base<false, true> {
146 __sfinae_ctor_base() = default;
147 __sfinae_ctor_base(__sfinae_ctor_base const&) = delete;
148 __sfinae_ctor_base(__sfinae_ctor_base &&) = default;
149 __sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default;
150 __sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default;
153 template <bool _CanCopy, bool _CanMove>
154 struct __sfinae_assign_base {};
155 template <>
156 struct __sfinae_assign_base<false, false> {
157 __sfinae_assign_base() = default;
158 __sfinae_assign_base(__sfinae_assign_base const&) = default;
159 __sfinae_assign_base(__sfinae_assign_base &&) = default;
160 __sfinae_assign_base& operator=(__sfinae_assign_base const&) = delete;
161 __sfinae_assign_base& operator=(__sfinae_assign_base&&) = delete;
163 template <>
164 struct __sfinae_assign_base<true, false> {
165 __sfinae_assign_base() = default;
166 __sfinae_assign_base(__sfinae_assign_base const&) = default;
167 __sfinae_assign_base(__sfinae_assign_base &&) = default;
168 __sfinae_assign_base& operator=(__sfinae_assign_base const&) = default;
169 __sfinae_assign_base& operator=(__sfinae_assign_base&&) = delete;
171 template <>
172 struct __sfinae_assign_base<false, true> {
173 __sfinae_assign_base() = default;
174 __sfinae_assign_base(__sfinae_assign_base const&) = default;
175 __sfinae_assign_base(__sfinae_assign_base &&) = default;
176 __sfinae_assign_base& operator=(__sfinae_assign_base const&) = delete;
177 __sfinae_assign_base& operator=(__sfinae_assign_base&&) = default;
179 #endif // _LIBCPP_STD_VER >= 17
181 _LIBCPP_END_NAMESPACE_STD
183 #endif // _LIBCPP___TUPLE_SFINAE_HELPERS_H