Skip to content

Commit 091c33b

Browse files
authored
[libc++] Remove SFINAE on __tuple_impl constructors (#151654)
The SFINAE isn't required, since the primary `tuple` class already does the SFINAE checks. This removes a bit of code that was only used for these constraints. This also moves the `tuple_element` specialization for `tuple` to `__fwd/tuple.h` to avoid a dependency on `__tuple/sfinae_helpers.h` (which should be moved in a follow-up).
1 parent 87283db commit 091c33b

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
@@ -233,7 +233,6 @@ template <class... Types>
233233
# include <__tuple/find_index.h>
234234
# include <__tuple/ignore.h>
235235
# include <__tuple/make_tuple_types.h>
236-
# include <__tuple/sfinae_helpers.h>
237236
# include <__tuple/tuple_element.h>
238237
# include <__tuple/tuple_like.h>
239238
# include <__tuple/tuple_like_ext.h>
@@ -247,7 +246,6 @@ template <class... Types>
247246
# include <__type_traits/disjunction.h>
248247
# include <__type_traits/enable_if.h>
249248
# include <__type_traits/invoke.h>
250-
# include <__type_traits/is_arithmetic.h>
251249
# include <__type_traits/is_assignable.h>
252250
# include <__type_traits/is_constructible.h>
253251
# include <__type_traits/is_convertible.h>
@@ -274,7 +272,6 @@ template <class... Types>
274272
# include <__utility/forward.h>
275273
# include <__utility/integer_sequence.h>
276274
# include <__utility/move.h>
277-
# include <__utility/piecewise_construct.h>
278275
# include <__utility/swap.h>
279276
# include <version>
280277

@@ -540,7 +537,7 @@ struct _LIBCPP_DECLSPEC_EMPTY_BASES
540537
allocator_arg_t, const _Alloc& __alloc, __forward_args, _Args&&... __args)
541538
: __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, _Args>(), __alloc, std::forward<_Args>(__args))... {}
542539

543-
template <class _Tuple, __enable_if_t<__tuple_constructible<_Tuple, tuple<_Tp...> >::value, int> = 0>
540+
template <class _Tuple>
544541
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_impl(_Tuple&& __t) noexcept(
545542
(__all<is_nothrow_constructible<
546543
_Tp,
@@ -549,7 +546,7 @@ struct _LIBCPP_DECLSPEC_EMPTY_BASES
549546
std::forward<typename tuple_element<_Indx, typename __make_tuple_types<_Tuple>::type>::type>(
550547
std::get<_Indx>(__t)))... {}
551548

552-
template <class _Alloc, class _Tuple, __enable_if_t<__tuple_constructible<_Tuple, tuple<_Tp...> >::value, int> = 0>
549+
template <class _Alloc, class _Tuple>
553550
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
554551
: __tuple_leaf<_Indx, _Tp>(
555552
__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)