[libcxx-commits] [libcxx] [libc++] Make __type_list variadic (PR #121117)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Dec 25 15:00:58 PST 2024
https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/121117
None
>From b60d782efc20358ddad762f8a85c42e4fc240c6b Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Thu, 26 Dec 2024 00:00:36 +0100
Subject: [PATCH] [libc++] Make __type_list variadic
---
.../include/__type_traits/aligned_storage.h | 37 +++++++++----------
libcxx/include/__type_traits/make_signed.h | 22 +++++------
libcxx/include/__type_traits/make_unsigned.h | 22 +++++------
libcxx/include/__type_traits/type_list.h | 28 ++++++++------
4 files changed, 53 insertions(+), 56 deletions(-)
diff --git a/libcxx/include/__type_traits/aligned_storage.h b/libcxx/include/__type_traits/aligned_storage.h
index 2e39afb7f88088..5cd1f587b988c5 100644
--- a/libcxx/include/__type_traits/aligned_storage.h
+++ b/libcxx/include/__type_traits/aligned_storage.h
@@ -34,26 +34,23 @@ struct __struct_double4 {
double __lx[4];
};
-// clang-format off
-typedef __type_list<__align_type<unsigned char>,
- __type_list<__align_type<unsigned short>,
- __type_list<__align_type<unsigned int>,
- __type_list<__align_type<unsigned long>,
- __type_list<__align_type<unsigned long long>,
- __type_list<__align_type<double>,
- __type_list<__align_type<long double>,
- __type_list<__align_type<__struct_double>,
- __type_list<__align_type<__struct_double4>,
- __type_list<__align_type<int*>,
- __nat
- > > > > > > > > > > __all_types;
-// clang-format on
+using __all_types =
+ __type_list<__align_type<unsigned char>,
+ __align_type<unsigned short>,
+ __align_type<unsigned int>,
+ __align_type<unsigned long>,
+ __align_type<unsigned long long>,
+ __align_type<double>,
+ __align_type<long double>,
+ __align_type<__struct_double>,
+ __align_type<__struct_double4>,
+ __align_type<int*> >;
template <class _TL, size_t _Len>
struct __find_max_align;
-template <class _Hp, size_t _Len>
-struct __find_max_align<__type_list<_Hp, __nat>, _Len> : public integral_constant<size_t, _Hp::value> {};
+template <class _Head, size_t _Len>
+struct __find_max_align<__type_list<_Head>, _Len> : public integral_constant<size_t, _Head::value> {};
template <size_t _Len, size_t _A1, size_t _A2>
struct __select_align {
@@ -65,9 +62,11 @@ struct __select_align {
static const size_t value = _Len < __max ? __min : __max;
};
-template <class _Hp, class _Tp, size_t _Len>
-struct __find_max_align<__type_list<_Hp, _Tp>, _Len>
- : public integral_constant<size_t, __select_align<_Len, _Hp::value, __find_max_align<_Tp, _Len>::value>::value> {};
+template <class _Head, class... _Tail, size_t _Len>
+struct __find_max_align<__type_list<_Head, _Tail...>, _Len>
+ : public integral_constant<
+ size_t,
+ __select_align<_Len, _Head::value, __find_max_align<__type_list<_Tail...>, _Len>::value>::value> {};
template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
struct _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_TEMPLATE_VIS aligned_storage {
diff --git a/libcxx/include/__type_traits/make_signed.h b/libcxx/include/__type_traits/make_signed.h
index 8070690b3a7a90..5c2739e6743526 100644
--- a/libcxx/include/__type_traits/make_signed.h
+++ b/libcxx/include/__type_traits/make_signed.h
@@ -29,21 +29,17 @@ template <class _Tp>
using __make_signed_t = __make_signed(_Tp);
#else
-// clang-format off
-typedef __type_list<signed char,
- __type_list<signed short,
- __type_list<signed int,
- __type_list<signed long,
- __type_list<signed long long,
-# if _LIBCPP_HAS_INT128
- __type_list<__int128_t,
-# endif
- __nat
+using __signed_types =
+ __type_list<signed char,
+ signed short,
+ signed int,
+ signed long,
+ signed long long
# if _LIBCPP_HAS_INT128
- >
+ ,
+ __int128_t
# endif
- > > > > > __signed_types;
-// clang-format on
+ >;
template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
struct __make_signed{};
diff --git a/libcxx/include/__type_traits/make_unsigned.h b/libcxx/include/__type_traits/make_unsigned.h
index 562f7bab8a7fbf..dfcfcaf1a74257 100644
--- a/libcxx/include/__type_traits/make_unsigned.h
+++ b/libcxx/include/__type_traits/make_unsigned.h
@@ -31,21 +31,17 @@ template <class _Tp>
using __make_unsigned_t = __make_unsigned(_Tp);
#else
-// clang-format off
-typedef __type_list<unsigned char,
- __type_list<unsigned short,
- __type_list<unsigned int,
- __type_list<unsigned long,
- __type_list<unsigned long long,
-# if _LIBCPP_HAS_INT128
- __type_list<__uint128_t,
-# endif
- __nat
+using __unsigned_types =
+ __type_list<unsigned char,
+ unsigned short,
+ unsigned int,
+ unsigned long,
+ unsigned long long,
# if _LIBCPP_HAS_INT128
- >
+ ,
+ __uint128_t
# endif
- > > > > > __unsigned_types;
-// clang-format on
+ >;
template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
struct __make_unsigned{};
diff --git a/libcxx/include/__type_traits/type_list.h b/libcxx/include/__type_traits/type_list.h
index b4898b36e2d905..e7d82d2b389d39 100644
--- a/libcxx/include/__type_traits/type_list.h
+++ b/libcxx/include/__type_traits/type_list.h
@@ -11,6 +11,7 @@
#include <__config>
#include <__cstddef/size_t.h>
+#include <__type_traits/enable_if.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -18,23 +19,28 @@
_LIBCPP_BEGIN_NAMESPACE_STD
-template <class _Hp, class _Tp>
-struct __type_list {
- typedef _Hp _Head;
- typedef _Tp _Tail;
+template <class... _Types>
+struct __type_list {};
+
+template <class>
+struct __type_list_head;
+
+template <class _Head, class... _Tail>
+struct __type_list_head<__type_list<_Head, _Tail...> > {
+ using type _LIBCPP_NODEBUG = _Head;
};
-template <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename _TypeList::_Head)>
+template <class _TypeList, size_t _Size, bool = _Size <= sizeof(__type_list_head<_TypeList>)>
struct __find_first;
-template <class _Hp, class _Tp, size_t _Size>
-struct __find_first<__type_list<_Hp, _Tp>, _Size, true> {
- using type _LIBCPP_NODEBUG = _Hp;
+template <class _Head, class... _Tail, size_t _Size>
+struct __find_first<__type_list<_Head, _Tail...>, _Size, true> {
+ using type _LIBCPP_NODEBUG = _Head;
};
-template <class _Hp, class _Tp, size_t _Size>
-struct __find_first<__type_list<_Hp, _Tp>, _Size, false> {
- using type _LIBCPP_NODEBUG = typename __find_first<_Tp, _Size>::type;
+template <class _Head, class... _Tail, size_t _Size>
+struct __find_first<__type_list<_Head, _Tail...>, _Size, false> {
+ using type _LIBCPP_NODEBUG = typename __find_first<__type_list<_Tail...>, _Size>::type;
};
_LIBCPP_END_NAMESPACE_STD
More information about the libcxx-commits
mailing list