Skip to content

[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 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions libcxx/include/__type_traits/aligned_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
22 changes: 9 additions & 13 deletions libcxx/include/__type_traits/make_signed.h
Original file line number Diff line number Diff line change
Expand Up @@ -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{};
Expand Down
22 changes: 9 additions & 13 deletions libcxx/include/__type_traits/make_unsigned.h
Original file line number Diff line number Diff line change
Expand Up @@ -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{};
Expand Down
28 changes: 17 additions & 11 deletions libcxx/include/__type_traits/type_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,36 @@

#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
#endif

_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
Expand Down
Loading