-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc++] Make __type_list variadic #121117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b60d782
to
4c464a7
Compare
4c464a7
to
a167c9d
Compare
@llvm/pr-subscribers-libcxx Author: Nikolas Klauser (philnik777) ChangesThis makes these lists signficiantly more readable. Full diff: https://github.com/llvm/llvm-project/pull/121117.diff 4 Files Affected:
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..6c238685c23316 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..34d78fc97c9780 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(typename __type_list_head<_TypeList>::type)>
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
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This makes these lists signficiantly more readable.