Skip to content

Commit 4c14389

Browse files
committed
[libc++] Simplify <tuple> further
1 parent 3a1298b commit 4c14389

File tree

8 files changed

+37
-147
lines changed

8 files changed

+37
-147
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,6 @@ set(files
778778
__tree
779779
__tuple/find_index.h
780780
__tuple/ignore.h
781-
__tuple/make_tuple_types.h
782781
__tuple/sfinae_helpers.h
783782
__tuple/tuple_element.h
784783
__tuple/tuple_like.h

libcxx/include/__fwd/tuple.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2121
template <size_t, class>
2222
struct tuple_element;
2323

24+
template <size_t _Np, class _Tp>
25+
using __tuple_element_t = typename tuple_element<_Np, _Tp>::type;
26+
2427
#ifndef _LIBCPP_CXX03_LANG
2528

2629
template <class...>

libcxx/include/__tuple/make_tuple_types.h

Lines changed: 0 additions & 77 deletions
This file was deleted.

libcxx/include/__tuple/tuple_element.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include <__config>
1313
#include <__cstddef/size_t.h>
14-
#include <__tuple/tuple_types.h>
1514

1615
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1716
# pragma GCC system_header
@@ -37,21 +36,11 @@ struct tuple_element<_Ip, const volatile _Tp> {
3736
using type _LIBCPP_NODEBUG = const volatile typename tuple_element<_Ip, _Tp>::type;
3837
};
3938

40-
#ifndef _LIBCPP_CXX03_LANG
41-
42-
template <size_t _Ip, class... _Types>
43-
struct tuple_element<_Ip, __tuple_types<_Types...> > {
44-
static_assert(_Ip < sizeof...(_Types), "tuple_element index out of range");
45-
using type _LIBCPP_NODEBUG = __type_pack_element<_Ip, _Types...>;
46-
};
47-
4839
# if _LIBCPP_STD_VER >= 14
4940
template <size_t _Ip, class... _Tp>
5041
using tuple_element_t _LIBCPP_NODEBUG = typename tuple_element<_Ip, _Tp...>::type;
5142
# endif
5243

53-
#endif // _LIBCPP_CXX03_LANG
54-
5544
_LIBCPP_END_NAMESPACE_STD
5645

5746
#endif // _LIBCPP___TUPLE_TUPLE_ELEMENT_H

libcxx/include/__tuple/tuple_like_ext.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <__fwd/array.h>
1515
#include <__fwd/pair.h>
1616
#include <__fwd/tuple.h>
17-
#include <__tuple/tuple_types.h>
1817
#include <__type_traits/integral_constant.h>
1918

2019
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -26,13 +25,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2625
template <class _Tp>
2726
struct __tuple_like_ext : false_type {};
2827

29-
template <class _Tp>
30-
struct __tuple_like_ext<const _Tp> : public __tuple_like_ext<_Tp> {};
31-
template <class _Tp>
32-
struct __tuple_like_ext<volatile _Tp> : public __tuple_like_ext<_Tp> {};
33-
template <class _Tp>
34-
struct __tuple_like_ext<const volatile _Tp> : public __tuple_like_ext<_Tp> {};
35-
3628
#ifndef _LIBCPP_CXX03_LANG
3729
template <class... _Tp>
3830
struct __tuple_like_ext<tuple<_Tp...> > : true_type {};
@@ -44,9 +36,6 @@ struct __tuple_like_ext<pair<_T1, _T2> > : true_type {};
4436
template <class _Tp, size_t _Size>
4537
struct __tuple_like_ext<array<_Tp, _Size> > : true_type {};
4638

47-
template <class... _Tp>
48-
struct __tuple_like_ext<__tuple_types<_Tp...> > : true_type {};
49-
5039
_LIBCPP_END_NAMESPACE_STD
5140

5241
#endif // _LIBCPP___TUPLE_TUPLE_LIKE_EXT_H

libcxx/include/__tuple/tuple_size.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ struct tuple_size<const volatile _Tp> : public tuple_size<_Tp> {};
5959
template <class... _Tp>
6060
struct tuple_size<tuple<_Tp...> > : public integral_constant<size_t, sizeof...(_Tp)> {};
6161

62-
template <class... _Tp>
63-
struct tuple_size<__tuple_types<_Tp...> > : public integral_constant<size_t, sizeof...(_Tp)> {};
64-
6562
# if _LIBCPP_STD_VER >= 17
6663
template <class _Tp>
6764
inline constexpr size_t tuple_size_v = tuple_size<_Tp>::value;

libcxx/include/module.modulemap.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2109,7 +2109,6 @@ module std [system] {
21092109
module tuple {
21102110
module find_index { header "__tuple/find_index.h" }
21112111
module ignore { header "__tuple/ignore.h" }
2112-
module make_tuple_types { header "__tuple/make_tuple_types.h" }
21132112
module sfinae_helpers { header "__tuple/sfinae_helpers.h" }
21142113
module tuple_element { header "__tuple/tuple_element.h" }
21152114
module tuple_like_ext { header "__tuple/tuple_like_ext.h" }

libcxx/include/tuple

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ template <class... Types>
232232
# include <__memory/uses_allocator.h>
233233
# include <__tuple/find_index.h>
234234
# include <__tuple/ignore.h>
235-
# include <__tuple/make_tuple_types.h>
236235
# include <__tuple/tuple_element.h>
237236
# include <__tuple/tuple_like.h>
238237
# include <__tuple/tuple_like_ext.h>
@@ -534,11 +533,10 @@ struct _LIBCPP_DECLSPEC_EMPTY_BASES
534533

535534
template <class _Tuple>
536535
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_impl(__from_tuple, _Tuple&& __t) noexcept(
537-
(__all<is_nothrow_constructible<
538-
_Tp,
539-
typename tuple_element<_Indx, typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
536+
(__all<is_nothrow_constructible<_Tp, __copy_cvref_t<_Tuple, __tuple_element_t<_Indx, __remove_cvref_t<_Tuple>>>>::
537+
value...>::value))
540538
: __tuple_leaf<_Indx, _Tp>(
541-
std::forward<typename tuple_element<_Indx, typename __make_tuple_types<_Tuple>::type>::type>(
539+
std::forward<__copy_cvref_t<_Tuple, __tuple_element_t<_Indx, __remove_cvref_t<_Tuple>>>>(
542540
std::get<_Indx>(__t)))... {}
543541

544542
template <class _Alloc, class _Tuple>
@@ -547,9 +545,9 @@ struct _LIBCPP_DECLSPEC_EMPTY_BASES
547545
: __tuple_leaf<_Indx, _Tp>(
548546
__uses_alloc_ctor<_Tp,
549547
_Alloc,
550-
typename tuple_element<_Indx, typename __make_tuple_types<_Tuple>::type>::type>(),
548+
__copy_cvref_t<_Tuple, __tuple_element_t<_Indx, __remove_cvref_t<_Tuple>>>>(),
551549
__a,
552-
std::forward<typename tuple_element<_Indx, typename __make_tuple_types<_Tuple>::type>::type>(
550+
std::forward<__copy_cvref_t<_Tuple, __tuple_element_t<_Indx, __remove_cvref_t<_Tuple>>>>(
553551
std::get<_Indx>(__t)))... {}
554552

555553
__tuple_impl(const __tuple_impl&) = default;
@@ -1272,47 +1270,36 @@ operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
12721270

12731271
// tuple_cat
12741272

1275-
template <class _Tp, class _Up>
1276-
struct __tuple_cat_type;
1273+
template <class... _Tuples>
1274+
struct __tuple_cat_return_impl;
12771275

1278-
template <class... _Ttypes, class... _Utypes>
1279-
struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> > {
1280-
using type _LIBCPP_NODEBUG = tuple<_Ttypes..., _Utypes...>;
1276+
template <class _Tuple>
1277+
struct __tuple_cat_return_impl<_Tuple> {
1278+
using type _LIBCPP_NODEBUG = _Tuple;
12811279
};
12821280

1283-
template <class _ResultTuple, bool _Is_Tuple0TupleLike, class... _Tuples>
1284-
struct __tuple_cat_return_1 {};
1281+
template <class... _Types0, template <class...> class _Tuple, class... _Types1, class... _Tuples>
1282+
struct __tuple_cat_return_impl<tuple<_Types0...>, _Tuple<_Types1...>, _Tuples...>
1283+
: __tuple_cat_return_impl<tuple<_Types0..., _Types1...>, _Tuples...> {};
12851284

1286-
template <class... _Types, class _Tuple0>
1287-
struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0> {
1288-
using type _LIBCPP_NODEBUG =
1289-
typename __tuple_cat_type< tuple<_Types...>,
1290-
typename __make_tuple_types<__remove_cvref_t<_Tuple0> >::type >::type;
1291-
};
1285+
template <class, class, class>
1286+
struct __tuple_cat_array;
12921287

1293-
template <class... _Types, class _Tuple0, class _Tuple1, class... _Tuples>
1294-
struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
1295-
: public __tuple_cat_return_1<
1296-
typename __tuple_cat_type< tuple<_Types...>,
1297-
typename __make_tuple_types<__remove_cvref_t<_Tuple0> >::type >::type,
1298-
__tuple_like_ext<__libcpp_remove_reference_t<_Tuple1> >::value,
1299-
_Tuple1,
1300-
_Tuples...> {};
1288+
template <class... _Types, class _ValueT, size_t... _Indices>
1289+
struct __tuple_cat_array<tuple<_Types...>, _ValueT, __index_sequence<_Indices...>> {
1290+
template <size_t>
1291+
using __value_type = _ValueT;
13011292

1302-
template <class... _Tuples>
1303-
struct __tuple_cat_return;
1293+
using type _LIBCPP_NODEBUG = tuple<_Types..., __value_type<_Indices>...>;
1294+
};
13041295

1305-
template <class _Tuple0, class... _Tuples>
1306-
struct __tuple_cat_return<_Tuple0, _Tuples...>
1307-
: public __tuple_cat_return_1<tuple<>,
1308-
__tuple_like_ext<__libcpp_remove_reference_t<_Tuple0> >::value,
1309-
_Tuple0,
1310-
_Tuples...> {};
1296+
template <class... _Types, class _ValueT, size_t _Np, class... _Tuples>
1297+
struct __tuple_cat_return_impl<tuple<_Types...>, array<_ValueT, _Np>, _Tuples...>
1298+
: __tuple_cat_return_impl<typename __tuple_cat_array<tuple<_Types...>, _ValueT, __make_index_sequence<_Np>>::type,
1299+
_Tuples...> {};
13111300

1312-
template <>
1313-
struct __tuple_cat_return<> {
1314-
using type _LIBCPP_NODEBUG = tuple<>;
1315-
};
1301+
template <class... _Tuples>
1302+
using __tuple_cat_return_t = typename __tuple_cat_return_impl<tuple<>, __remove_cvref_t<_Tuples>...>::type;
13161303

13171304
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 tuple<> tuple_cat() { return tuple<>(); }
13181305

@@ -1381,11 +1368,15 @@ __tuple_cat_select_element_wise(_TupleSrc&& __src, __index_sequence<_Indices...>
13811368
return _TupleDst(std::get<_Indices>(std::forward<_TupleSrc>(__src))...);
13821369
}
13831370

1384-
template <class _Tuple0, class... _Tuples>
1385-
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 typename __tuple_cat_return<_Tuple0, _Tuples...>::type
1371+
template <class _Tuple0,
1372+
class... _Tuples,
1373+
__enable_if_t<
1374+
_And<__tuple_like_ext<__remove_cvref_t<_Tuple0>>, __tuple_like_ext<__remove_cvref_t<_Tuples>>...>::value,
1375+
int> = 0>
1376+
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_cat_return_t<_Tuple0, _Tuples...>
13861377
tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls) {
13871378
using _T0 _LIBCPP_NODEBUG = __libcpp_remove_reference_t<_Tuple0>;
1388-
using _TRet _LIBCPP_NODEBUG = typename __tuple_cat_return<_Tuple0, _Tuples...>::type;
1379+
using _TRet _LIBCPP_NODEBUG = __tuple_cat_return_t<_Tuple0, _Tuples...>;
13891380
using _T0Indices _LIBCPP_NODEBUG = __make_index_sequence<tuple_size<_T0>::value>;
13901381
using _TRetIndices _LIBCPP_NODEBUG = __make_index_sequence<tuple_size<_TRet>::value>;
13911382
return std::__tuple_cat_select_element_wise<_TRet>(

0 commit comments

Comments
 (0)