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 //===----------------------------------------------------------------------===// 8 9 #ifndef _LIBCPP___TUPLE_SFINAE_HELPERS_H 10 #define _LIBCPP___TUPLE_SFINAE_HELPERS_H 11 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> 28 29 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 30 # pragma GCC system_header 31 #endif 32 33 _LIBCPP_BEGIN_NAMESPACE_STD 34 35 #ifndef _LIBCPP_CXX03_LANG 36 37 template <bool... _Preds> 38 struct __all_dummy; 39 40 template <bool... _Pred> 41 struct __all : _IsSame<__all_dummy<_Pred...>, __all_dummy<((void)_Pred, true)...>> {}; 42 43 struct __tuple_sfinae_base { 44 template <template <class, class...> class _Trait, class... _LArgs, class... _RArgs> 45 static auto __do_test(__tuple_types<_LArgs...>, __tuple_types<_RArgs...>) 46 -> __all<__enable_if_t<_Trait<_LArgs, _RArgs>::value, bool>{true}...>; 47 template <template <class...> class> 48 static auto __do_test(...) -> false_type; 49 50 template <class _FromArgs, class _ToArgs> 51 using __constructible = decltype(__do_test<is_constructible>(_ToArgs{}, _FromArgs{})); 52 template <class _FromArgs, class _ToArgs> 53 using __convertible = decltype(__do_test<is_convertible>(_FromArgs{}, _ToArgs{})); 54 template <class _FromArgs, class _ToArgs> 55 using __assignable = decltype(__do_test<is_assignable>(_ToArgs{}, _FromArgs{})); 56 }; 57 58 // __tuple_convertible 59 60 template <class _Tp, 61 class _Up, 62 bool = __tuple_like_ext<__libcpp_remove_reference_t<_Tp> >::value, 63 bool = __tuple_like_ext<_Up>::value> 64 struct __tuple_convertible : public false_type {}; 65 66 template <class _Tp, class _Up> 67 struct __tuple_convertible<_Tp, _Up, true, true> 68 : public __tuple_sfinae_base::__convertible< typename __make_tuple_types<_Tp>::type, 69 typename __make_tuple_types<_Up>::type > {}; 70 71 // __tuple_constructible 72 73 template <class _Tp, 74 class _Up, 75 bool = __tuple_like_ext<__libcpp_remove_reference_t<_Tp> >::value, 76 bool = __tuple_like_ext<_Up>::value> 77 struct __tuple_constructible : public false_type {}; 78 79 template <class _Tp, class _Up> 80 struct __tuple_constructible<_Tp, _Up, true, true> 81 : public __tuple_sfinae_base::__constructible< typename __make_tuple_types<_Tp>::type, 82 typename __make_tuple_types<_Up>::type > {}; 83 84 // __tuple_assignable 85 86 template <class _Tp, 87 class _Up, 88 bool = __tuple_like_ext<__libcpp_remove_reference_t<_Tp> >::value, 89 bool = __tuple_like_ext<_Up>::value> 90 struct __tuple_assignable : public false_type {}; 91 92 template <class _Tp, class _Up> 93 struct __tuple_assignable<_Tp, _Up, true, true> 94 : public __tuple_sfinae_base::__assignable< typename __make_tuple_types<_Tp>::type, 95 typename __make_tuple_types<_Up&>::type > {}; 96 97 template <size_t _Ip, class... _Tp> 98 struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, tuple<_Tp...> > { 99 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type; 100 }; 101 102 struct _LIBCPP_EXPORTED_FROM_ABI __check_tuple_constructor_fail { 103 static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_explicit_default() { return false; } 104 static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_implicit_default() { return false; } 105 template <class...> 106 static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_explicit() { 107 return false; 108 } 109 template <class...> 110 static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_implicit() { 111 return false; 112 } 113 template <class...> 114 static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_assign() { 115 return false; 116 } 117 }; 118 #endif // !defined(_LIBCPP_CXX03_LANG) 119 120 #if _LIBCPP_STD_VER >= 17 121 122 template <bool _CanCopy, bool _CanMove> 123 struct __sfinae_ctor_base {}; 124 template <> 125 struct __sfinae_ctor_base<false, false> { 126 __sfinae_ctor_base() = default; 127 __sfinae_ctor_base(__sfinae_ctor_base const&) = delete; 128 __sfinae_ctor_base(__sfinae_ctor_base&&) = delete; 129 __sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default; 130 __sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default; 131 }; 132 template <> 133 struct __sfinae_ctor_base<true, false> { 134 __sfinae_ctor_base() = default; 135 __sfinae_ctor_base(__sfinae_ctor_base const&) = default; 136 __sfinae_ctor_base(__sfinae_ctor_base&&) = delete; 137 __sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default; 138 __sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default; 139 }; 140 template <> 141 struct __sfinae_ctor_base<false, true> { 142 __sfinae_ctor_base() = default; 143 __sfinae_ctor_base(__sfinae_ctor_base const&) = delete; 144 __sfinae_ctor_base(__sfinae_ctor_base&&) = default; 145 __sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default; 146 __sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default; 147 }; 148 149 template <bool _CanCopy, bool _CanMove> 150 struct __sfinae_assign_base {}; 151 template <> 152 struct __sfinae_assign_base<false, false> { 153 __sfinae_assign_base() = default; 154 __sfinae_assign_base(__sfinae_assign_base const&) = default; 155 __sfinae_assign_base(__sfinae_assign_base&&) = default; 156 __sfinae_assign_base& operator=(__sfinae_assign_base const&) = delete; 157 __sfinae_assign_base& operator=(__sfinae_assign_base&&) = delete; 158 }; 159 template <> 160 struct __sfinae_assign_base<true, false> { 161 __sfinae_assign_base() = default; 162 __sfinae_assign_base(__sfinae_assign_base const&) = default; 163 __sfinae_assign_base(__sfinae_assign_base&&) = default; 164 __sfinae_assign_base& operator=(__sfinae_assign_base const&) = default; 165 __sfinae_assign_base& operator=(__sfinae_assign_base&&) = delete; 166 }; 167 template <> 168 struct __sfinae_assign_base<false, true> { 169 __sfinae_assign_base() = default; 170 __sfinae_assign_base(__sfinae_assign_base const&) = default; 171 __sfinae_assign_base(__sfinae_assign_base&&) = default; 172 __sfinae_assign_base& operator=(__sfinae_assign_base const&) = delete; 173 __sfinae_assign_base& operator=(__sfinae_assign_base&&) = default; 174 }; 175 #endif // _LIBCPP_STD_VER >= 17 176 177 _LIBCPP_END_NAMESPACE_STD 178 179 #endif // _LIBCPP___TUPLE_SFINAE_HELPERS_H 180