Skip to content

Commit 40ac34c

Browse files
authored
[libc++] Make __type_list variadic (#121117)
This makes these lists signficiantly more readable.
1 parent 11e482c commit 40ac34c

File tree

4 files changed

+53
-56
lines changed

4 files changed

+53
-56
lines changed

libcxx/include/__type_traits/aligned_storage.h

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,23 @@ struct __struct_double4 {
3434
double __lx[4];
3535
};
3636

37-
// clang-format off
38-
typedef __type_list<__align_type<unsigned char>,
39-
__type_list<__align_type<unsigned short>,
40-
__type_list<__align_type<unsigned int>,
41-
__type_list<__align_type<unsigned long>,
42-
__type_list<__align_type<unsigned long long>,
43-
__type_list<__align_type<double>,
44-
__type_list<__align_type<long double>,
45-
__type_list<__align_type<__struct_double>,
46-
__type_list<__align_type<__struct_double4>,
47-
__type_list<__align_type<int*>,
48-
__nat
49-
> > > > > > > > > > __all_types;
50-
// clang-format on
37+
using __all_types =
38+
__type_list<__align_type<unsigned char>,
39+
__align_type<unsigned short>,
40+
__align_type<unsigned int>,
41+
__align_type<unsigned long>,
42+
__align_type<unsigned long long>,
43+
__align_type<double>,
44+
__align_type<long double>,
45+
__align_type<__struct_double>,
46+
__align_type<__struct_double4>,
47+
__align_type<int*> >;
5148

5249
template <class _TL, size_t _Len>
5350
struct __find_max_align;
5451

55-
template <class _Hp, size_t _Len>
56-
struct __find_max_align<__type_list<_Hp, __nat>, _Len> : public integral_constant<size_t, _Hp::value> {};
52+
template <class _Head, size_t _Len>
53+
struct __find_max_align<__type_list<_Head>, _Len> : public integral_constant<size_t, _Head::value> {};
5754

5855
template <size_t _Len, size_t _A1, size_t _A2>
5956
struct __select_align {
@@ -65,9 +62,11 @@ struct __select_align {
6562
static const size_t value = _Len < __max ? __min : __max;
6663
};
6764

68-
template <class _Hp, class _Tp, size_t _Len>
69-
struct __find_max_align<__type_list<_Hp, _Tp>, _Len>
70-
: public integral_constant<size_t, __select_align<_Len, _Hp::value, __find_max_align<_Tp, _Len>::value>::value> {};
65+
template <class _Head, class... _Tail, size_t _Len>
66+
struct __find_max_align<__type_list<_Head, _Tail...>, _Len>
67+
: public integral_constant<
68+
size_t,
69+
__select_align<_Len, _Head::value, __find_max_align<__type_list<_Tail...>, _Len>::value>::value> {};
7170

7271
template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
7372
struct _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_TEMPLATE_VIS aligned_storage {

libcxx/include/__type_traits/make_signed.h

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,17 @@ template <class _Tp>
2929
using __make_signed_t = __make_signed(_Tp);
3030

3131
#else
32-
// clang-format off
33-
typedef __type_list<signed char,
34-
__type_list<signed short,
35-
__type_list<signed int,
36-
__type_list<signed long,
37-
__type_list<signed long long,
38-
# if _LIBCPP_HAS_INT128
39-
__type_list<__int128_t,
40-
# endif
41-
__nat
32+
using __signed_types =
33+
__type_list<signed char,
34+
signed short,
35+
signed int,
36+
signed long,
37+
signed long long
4238
# if _LIBCPP_HAS_INT128
43-
>
39+
,
40+
__int128_t
4441
# endif
45-
> > > > > __signed_types;
46-
// clang-format on
42+
>;
4743

4844
template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
4945
struct __make_signed{};

libcxx/include/__type_traits/make_unsigned.h

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,17 @@ template <class _Tp>
3131
using __make_unsigned_t = __make_unsigned(_Tp);
3232

3333
#else
34-
// clang-format off
35-
typedef __type_list<unsigned char,
36-
__type_list<unsigned short,
37-
__type_list<unsigned int,
38-
__type_list<unsigned long,
39-
__type_list<unsigned long long,
40-
# if _LIBCPP_HAS_INT128
41-
__type_list<__uint128_t,
42-
# endif
43-
__nat
34+
using __unsigned_types =
35+
__type_list<unsigned char,
36+
unsigned short,
37+
unsigned int,
38+
unsigned long,
39+
unsigned long long
4440
# if _LIBCPP_HAS_INT128
45-
>
41+
,
42+
__uint128_t
4643
# endif
47-
> > > > > __unsigned_types;
48-
// clang-format on
44+
>;
4945

5046
template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
5147
struct __make_unsigned{};

libcxx/include/__type_traits/type_list.h

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,36 @@
1111

1212
#include <__config>
1313
#include <__cstddef/size_t.h>
14+
#include <__type_traits/enable_if.h>
1415

1516
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1617
# pragma GCC system_header
1718
#endif
1819

1920
_LIBCPP_BEGIN_NAMESPACE_STD
2021

21-
template <class _Hp, class _Tp>
22-
struct __type_list {
23-
typedef _Hp _Head;
24-
typedef _Tp _Tail;
22+
template <class... _Types>
23+
struct __type_list {};
24+
25+
template <class>
26+
struct __type_list_head;
27+
28+
template <class _Head, class... _Tail>
29+
struct __type_list_head<__type_list<_Head, _Tail...> > {
30+
using type _LIBCPP_NODEBUG = _Head;
2531
};
2632

27-
template <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename _TypeList::_Head)>
33+
template <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename __type_list_head<_TypeList>::type)>
2834
struct __find_first;
2935

30-
template <class _Hp, class _Tp, size_t _Size>
31-
struct __find_first<__type_list<_Hp, _Tp>, _Size, true> {
32-
using type _LIBCPP_NODEBUG = _Hp;
36+
template <class _Head, class... _Tail, size_t _Size>
37+
struct __find_first<__type_list<_Head, _Tail...>, _Size, true> {
38+
using type _LIBCPP_NODEBUG = _Head;
3339
};
3440

35-
template <class _Hp, class _Tp, size_t _Size>
36-
struct __find_first<__type_list<_Hp, _Tp>, _Size, false> {
37-
using type _LIBCPP_NODEBUG = typename __find_first<_Tp, _Size>::type;
41+
template <class _Head, class... _Tail, size_t _Size>
42+
struct __find_first<__type_list<_Head, _Tail...>, _Size, false> {
43+
using type _LIBCPP_NODEBUG = typename __find_first<__type_list<_Tail...>, _Size>::type;
3844
};
3945

4046
_LIBCPP_END_NAMESPACE_STD

0 commit comments

Comments
 (0)