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/conjunction.h>
20#include <__type_traits/enable_if.h>
21#include <__type_traits/integral_constant.h>
22#include <__type_traits/is_constructible.h>
23#include <__type_traits/is_same.h>
24#include <__type_traits/remove_cvref.h>
25#include <__type_traits/remove_reference.h>
26#include <cstddef>
27
28#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
29# pragma GCC system_header
30#endif
31
32_LIBCPP_BEGIN_NAMESPACE_STD
33
34#ifndef _LIBCPP_CXX03_LANG
35
36struct __tuple_sfinae_base {
37 template <template <class, class...> class _Trait, class... _LArgs, class... _RArgs>
38 static auto __do_test(__tuple_types<_LArgs...>,
39 __tuple_types<_RArgs...>) -> __all<__enable_if_t<_Trait<_LArgs, _RArgs>::value, bool>{true}...>;
40 template <template <class...> class>
41 static auto __do_test(...) -> false_type;
42
43 template <class _FromArgs, class _ToArgs>
44 using __constructible = decltype(__do_test<is_constructible>(_ToArgs{}, _FromArgs{}));
45};
46
47// __tuple_constructible
48
49template <class _Tp,
50 class _Up,
51 bool = __tuple_like_ext<__libcpp_remove_reference_t<_Tp> >::value,
52 bool = __tuple_like_ext<_Up>::value>
53struct __tuple_constructible : public false_type {};
54
55template <class _Tp, class _Up>
56struct __tuple_constructible<_Tp, _Up, true, true>
57 : public __tuple_sfinae_base::__constructible< typename __make_tuple_types<_Tp>::type,
58 typename __make_tuple_types<_Up>::type > {};
59
60template <size_t _Ip, class... _Tp>
61struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, tuple<_Tp...> > {
62 typedef _LIBCPP_NODEBUG typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type;
63};
64
65struct _LIBCPP_EXPORTED_FROM_ABI __check_tuple_constructor_fail {
66 static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_explicit_default() { return false; }
67 static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_implicit_default() { return false; }
68 template <class...>
69 static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_explicit() {
70 return false;
71 }
72 template <class...>
73 static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_implicit() {
74 return false;
75 }
76 template <class...>
77 static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_assign() {
78 return false;
79 }
80};
81#endif // !defined(_LIBCPP_CXX03_LANG)
82
83#if _LIBCPP_STD_VER >= 17
84
85template <bool _CanCopy, bool _CanMove>
86struct __sfinae_ctor_base {};
87template <>
88struct __sfinae_ctor_base<false, false> {
89 __sfinae_ctor_base() = default;
90 __sfinae_ctor_base(__sfinae_ctor_base const&) = delete;
91 __sfinae_ctor_base(__sfinae_ctor_base&&) = delete;
92 __sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default;
93 __sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default;
94};
95template <>
96struct __sfinae_ctor_base<true, false> {
97 __sfinae_ctor_base() = default;
98 __sfinae_ctor_base(__sfinae_ctor_base const&) = default;
99 __sfinae_ctor_base(__sfinae_ctor_base&&) = delete;
100 __sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default;
101 __sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default;
102};
103template <>
104struct __sfinae_ctor_base<false, true> {
105 __sfinae_ctor_base() = default;
106 __sfinae_ctor_base(__sfinae_ctor_base const&) = delete;
107 __sfinae_ctor_base(__sfinae_ctor_base&&) = default;
108 __sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default;
109 __sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default;
110};
111
112template <bool _CanCopy, bool _CanMove>
113struct __sfinae_assign_base {};
114template <>
115struct __sfinae_assign_base<false, false> {
116 __sfinae_assign_base() = default;
117 __sfinae_assign_base(__sfinae_assign_base const&) = default;
118 __sfinae_assign_base(__sfinae_assign_base&&) = default;
119 __sfinae_assign_base& operator=(__sfinae_assign_base const&) = delete;
120 __sfinae_assign_base& operator=(__sfinae_assign_base&&) = delete;
121};
122template <>
123struct __sfinae_assign_base<true, false> {
124 __sfinae_assign_base() = default;
125 __sfinae_assign_base(__sfinae_assign_base const&) = default;
126 __sfinae_assign_base(__sfinae_assign_base&&) = default;
127 __sfinae_assign_base& operator=(__sfinae_assign_base const&) = default;
128 __sfinae_assign_base& operator=(__sfinae_assign_base&&) = delete;
129};
130template <>
131struct __sfinae_assign_base<false, true> {
132 __sfinae_assign_base() = default;
133 __sfinae_assign_base(__sfinae_assign_base const&) = default;
134 __sfinae_assign_base(__sfinae_assign_base&&) = default;
135 __sfinae_assign_base& operator=(__sfinae_assign_base const&) = delete;
136 __sfinae_assign_base& operator=(__sfinae_assign_base&&) = default;
137};
138#endif // _LIBCPP_STD_VER >= 17
139
140_LIBCPP_END_NAMESPACE_STD
141
142#endif // _LIBCPP___TUPLE_SFINAE_HELPERS_H
143