Skip to content

Commit 26bbd44

Browse files
committed
[libc++] Remove SFINAE on __tuple_impl constructors
1 parent f616127 commit 26bbd44

File tree

7 files changed

+14
-50
lines changed

7 files changed

+14
-50
lines changed

libcxx/include/__fwd/tuple.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ struct tuple_element;
2626
template <class...>
2727
class tuple;
2828

29+
template <size_t _Ip, class... _Tp>
30+
struct tuple_element<_Ip, tuple<_Tp...> > {
31+
using type _LIBCPP_NODEBUG = __type_pack_element<_Ip, _Tp...>;
32+
};
33+
2934
template <class>
3035
struct tuple_size;
3136

libcxx/include/__memory/uses_allocator_construction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <__type_traits/remove_cv.h>
1818
#include <__utility/declval.h>
1919
#include <__utility/pair.h>
20+
#include <__utility/piecewise_construct.h>
2021
#include <tuple>
2122

2223
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

libcxx/include/__memory_resource/polymorphic_allocator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <__new/exceptions.h>
1919
#include <__new/placement_new_delete.h>
2020
#include <__utility/exception_guard.h>
21+
#include <__utility/piecewise_construct.h>
2122
#include <limits>
2223
#include <tuple>
2324

libcxx/include/__tuple/sfinae_helpers.h

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,6 @@
1010
#define _LIBCPP___TUPLE_SFINAE_HELPERS_H
1111

1212
#include <__config>
13-
#include <__cstddef/size_t.h>
14-
#include <__fwd/tuple.h>
15-
#include <__tuple/make_tuple_types.h>
16-
#include <__tuple/tuple_element.h>
17-
#include <__tuple/tuple_like_ext.h>
18-
#include <__tuple/tuple_size.h>
19-
#include <__tuple/tuple_types.h>
20-
#include <__type_traits/conjunction.h>
21-
#include <__type_traits/enable_if.h>
22-
#include <__type_traits/integral_constant.h>
23-
#include <__type_traits/is_constructible.h>
24-
#include <__type_traits/is_same.h>
25-
#include <__type_traits/remove_cvref.h>
26-
#include <__type_traits/remove_reference.h>
2713

2814
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2915
# pragma GCC system_header
@@ -33,35 +19,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3319

3420
#ifndef _LIBCPP_CXX03_LANG
3521

36-
struct __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 _LIBCPP_NODEBUG = decltype(__do_test<is_constructible>(_ToArgs{}, _FromArgs{}));
45-
};
46-
47-
// __tuple_constructible
48-
49-
template <class _Tp,
50-
class _Up,
51-
bool = __tuple_like_ext<__libcpp_remove_reference_t<_Tp> >::value,
52-
bool = __tuple_like_ext<_Up>::value>
53-
struct __tuple_constructible : public false_type {};
54-
55-
template <class _Tp, class _Up>
56-
struct __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-
60-
template <size_t _Ip, class... _Tp>
61-
struct tuple_element<_Ip, tuple<_Tp...> > {
62-
using type _LIBCPP_NODEBUG = typename tuple_element<_Ip, __tuple_types<_Tp...> >::type;
63-
};
64-
6522
struct _LIBCPP_EXPORTED_FROM_ABI __check_tuple_constructor_fail {
6623
static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_explicit_default() { return false; }
6724
static _LIBCPP_HIDE_FROM_ABI constexpr bool __enable_implicit_default() { return false; }

libcxx/include/module.modulemap.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2168,7 +2168,10 @@ module std [system] {
21682168
module is_valid_range { header "__utility/is_valid_range.h" }
21692169
module move { header "__utility/move.h" }
21702170
module no_destroy { header "__utility/no_destroy.h" }
2171-
module pair { header "__utility/pair.h" }
2171+
module pair {
2172+
header "__utility/pair.h"
2173+
export std.utility.piecewise_construct
2174+
}
21722175
module piecewise_construct { header "__utility/piecewise_construct.h" }
21732176
module priority_tag { header "__utility/priority_tag.h" }
21742177
module private_constructor_tag { header "__utility/private_constructor_tag.h" }

libcxx/include/tuple

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ template <class... Types>
227227
# include <__tuple/find_index.h>
228228
# include <__tuple/ignore.h>
229229
# include <__tuple/make_tuple_types.h>
230-
# include <__tuple/sfinae_helpers.h>
231230
# include <__tuple/tuple_element.h>
232231
# include <__tuple/tuple_like_ext.h>
233232
# include <__tuple/tuple_size.h>
@@ -240,7 +239,6 @@ template <class... Types>
240239
# include <__type_traits/disjunction.h>
241240
# include <__type_traits/enable_if.h>
242241
# include <__type_traits/invoke.h>
243-
# include <__type_traits/is_arithmetic.h>
244242
# include <__type_traits/is_assignable.h>
245243
# include <__type_traits/is_constructible.h>
246244
# include <__type_traits/is_convertible.h>
@@ -267,7 +265,6 @@ template <class... Types>
267265
# include <__utility/forward.h>
268266
# include <__utility/integer_sequence.h>
269267
# include <__utility/move.h>
270-
# include <__utility/piecewise_construct.h>
271268
# include <__utility/swap.h>
272269
# include <version>
273270

@@ -471,7 +468,7 @@ struct _LIBCPP_DECLSPEC_EMPTY_BASES
471468
allocator_arg_t, const _Alloc& __alloc, __forward_args, _Args&&... __args)
472469
: __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, _Args>(), __alloc, std::forward<_Args>(__args))... {}
473470

474-
template <class _Tuple, __enable_if_t<__tuple_constructible<_Tuple, tuple<_Tp...> >::value, int> = 0>
471+
template <class _Tuple>
475472
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_impl(_Tuple&& __t) noexcept(
476473
(__all<is_nothrow_constructible<
477474
_Tp,
@@ -480,7 +477,7 @@ struct _LIBCPP_DECLSPEC_EMPTY_BASES
480477
std::forward<typename tuple_element<_Indx, typename __make_tuple_types<_Tuple>::type>::type>(
481478
std::get<_Indx>(__t)))... {}
482479

483-
template <class _Alloc, class _Tuple, __enable_if_t<__tuple_constructible<_Tuple, tuple<_Tp...> >::value, int> = 0>
480+
template <class _Alloc, class _Tuple>
484481
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
485482
: __tuple_leaf<_Indx, _Tp>(
486483
__uses_alloc_ctor<_Tp,

libcxx/test/std/utilities/tuple/tuple.tuple/tuple.helper/tuple_element.verify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
using T = std::tuple<int, long, void*>;
2424
using E1 = typename std::tuple_element<1, T &>::type; // expected-error{{undefined template}}
2525
using E2 = typename std::tuple_element<3, T>::type;
26-
using E3 = typename std::tuple_element<4, T const>::type; // expected-error@*:* 2 {{static assertion failed}}
26+
using E3 = typename std::tuple_element<4, T const>::type; // expected-error@*:* 2 {{out of bounds index}}

0 commit comments

Comments
 (0)