Skip to content

Commit d06fc33

Browse files
committed
[libc++][RFC] Use type traits builtins directly in <type_traits> and <concepts>
1 parent b07e7b7 commit d06fc33

31 files changed

+53
-105
lines changed

libcxx/include/__concepts/class_or_enum.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
#define _LIBCPP___CONCEPTS_CLASS_OR_ENUM_H
1111

1212
#include <__config>
13-
#include <__type_traits/is_class.h>
14-
#include <__type_traits/is_enum.h>
15-
#include <__type_traits/is_union.h>
16-
#include <__type_traits/remove_cvref.h>
1713

1814
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1915
# pragma GCC system_header
@@ -26,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2622
// Whether a type is a class type or enumeration type according to the Core wording.
2723

2824
template <class _Tp>
29-
concept __class_or_enum = is_class_v<_Tp> || is_union_v<_Tp> || is_enum_v<_Tp>;
25+
concept __class_or_enum = __is_class(_Tp) || __is_union(_Tp) || __is_enum(_Tp);
3026

3127
#endif // _LIBCPP_STD_VER >= 20
3228

libcxx/include/__concepts/constructible.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <__concepts/convertible_to.h>
1313
#include <__concepts/destructible.h>
1414
#include <__config>
15-
#include <__type_traits/is_constructible.h>
1615

1716
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1817
# pragma GCC system_header
@@ -24,7 +23,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2423

2524
// [concept.constructible]
2625
template <class _Tp, class... _Args>
27-
concept constructible_from = destructible<_Tp> && is_constructible_v<_Tp, _Args...>;
26+
concept constructible_from = destructible<_Tp> && __is_constructible(_Tp, _Args...);
2827

2928
// [concept.default.init]
3029

libcxx/include/__concepts/convertible_to.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2424
// [concept.convertible]
2525

2626
template <class _From, class _To>
27-
concept convertible_to = is_convertible_v<_From, _To> && requires { static_cast<_To>(std::declval<_From>()); };
27+
concept convertible_to = __is_convertible(_From, _To) && requires { static_cast<_To>(std::declval<_From>()); };
2828

2929
#endif // _LIBCPP_STD_VER >= 20
3030

libcxx/include/__concepts/derived_from.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#define _LIBCPP___CONCEPTS_DERIVED_FROM_H
1111

1212
#include <__config>
13-
#include <__type_traits/is_base_of.h>
14-
#include <__type_traits/is_convertible.h>
1513

1614
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1715
# pragma GCC system_header
@@ -24,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2422
// [concept.derived]
2523

2624
template <class _Dp, class _Bp>
27-
concept derived_from = is_base_of_v<_Bp, _Dp> && is_convertible_v<const volatile _Dp*, const volatile _Bp*>;
25+
concept derived_from = __is_base_of(_Bp, _Dp) && __is_convertible(const volatile _Dp*, const volatile _Bp*);
2826

2927
#endif // _LIBCPP_STD_VER >= 20
3028

libcxx/include/__concepts/different_from.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include <__concepts/same_as.h>
1313
#include <__config>
14-
#include <__type_traits/remove_cvref.h>
1514

1615
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1716
# pragma GCC system_header
@@ -22,7 +21,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2221
#if _LIBCPP_STD_VER >= 20
2322

2423
template <class _Tp, class _Up>
25-
concept __different_from = !same_as<remove_cvref_t<_Tp>, remove_cvref_t<_Up>>;
24+
concept __different_from = !same_as<__remove_cvref(_Tp), __remove_cvref(_Up)>;
2625

2726
#endif // _LIBCPP_STD_VER >= 20
2827

libcxx/include/__concepts/movable.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <__concepts/constructible.h>
1414
#include <__concepts/swappable.h>
1515
#include <__config>
16-
#include <__type_traits/is_object.h>
1716

1817
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1918
# pragma GCC system_header
@@ -26,7 +25,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2625
// [concepts.object]
2726

2827
template <class _Tp>
29-
concept movable = is_object_v<_Tp> && move_constructible<_Tp> && assignable_from<_Tp&, _Tp> && swappable<_Tp>;
28+
concept movable = __is_object(_Tp) && move_constructible<_Tp> && assignable_from<_Tp&, _Tp> && swappable<_Tp>;
3029

3130
#endif // _LIBCPP_STD_VER >= 20
3231

libcxx/include/__concepts/same_as.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#define _LIBCPP___CONCEPTS_SAME_AS_H
1111

1212
#include <__config>
13-
#include <__type_traits/is_same.h>
1413

1514
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1615
# pragma GCC system_header
@@ -23,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2322
// [concept.same]
2423

2524
template <class _Tp, class _Up>
26-
concept __same_as_impl = _IsSame<_Tp, _Up>::value;
25+
concept __same_as_impl = __is_same(_Tp, _Up);
2726

2827
template <class _Tp, class _Up>
2928
concept same_as = __same_as_impl<_Tp, _Up> && __same_as_impl<_Up, _Tp>;

libcxx/include/__concepts/swappable.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <__type_traits/extent.h>
1919
#include <__type_traits/is_nothrow_assignable.h>
2020
#include <__type_traits/is_nothrow_constructible.h>
21-
#include <__type_traits/remove_cvref.h>
2221
#include <__utility/exchange.h>
2322
#include <__utility/forward.h>
2423
#include <__utility/move.h>
@@ -46,7 +45,7 @@ void swap(_Tp&, _Tp&) = delete;
4645
// clang-format off
4746
template <class _Tp, class _Up>
4847
concept __unqualified_swappable_with =
49-
(__class_or_enum<remove_cvref_t<_Tp>> || __class_or_enum<remove_cvref_t<_Up>>) &&
48+
(__class_or_enum<__remove_cvref(_Tp)> || __class_or_enum<__remove_cvref(_Up)>) &&
5049
requires(_Tp&& __t, _Up&& __u) {
5150
swap(std::forward<_Tp>(__t), std::forward<_Up>(__u));
5251
};

libcxx/include/__type_traits/can_extract_key.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <__fwd/pair.h>
1414
#include <__type_traits/conditional.h>
1515
#include <__type_traits/integral_constant.h>
16-
#include <__type_traits/is_same.h>
1716
#include <__type_traits/remove_const.h>
1817
#include <__type_traits/remove_const_ref.h>
1918

@@ -29,19 +28,18 @@ struct __extract_key_self_tag {};
2928
struct __extract_key_first_tag {};
3029

3130
template <class _ValTy, class _Key, class _RawValTy = __remove_const_ref_t<_ValTy> >
32-
struct __can_extract_key
33-
: __conditional_t<_IsSame<_RawValTy, _Key>::value, __extract_key_self_tag, __extract_key_fail_tag> {};
31+
struct __can_extract_key : __conditional_t<__is_same(_RawValTy, _Key), __extract_key_self_tag, __extract_key_fail_tag> {
32+
};
3433

3534
template <class _Pair, class _Key, class _First, class _Second>
3635
struct __can_extract_key<_Pair, _Key, pair<_First, _Second> >
37-
: __conditional_t<_IsSame<__remove_const_t<_First>, _Key>::value, __extract_key_first_tag, __extract_key_fail_tag> {
38-
};
36+
: __conditional_t<__is_same(__remove_const_t<_First>, _Key), __extract_key_first_tag, __extract_key_fail_tag> {};
3937

4038
// __can_extract_map_key uses true_type/false_type instead of the tags.
4139
// It returns true if _Key != _ContainerValueTy (the container is a map not a set)
4240
// and _ValTy == _Key.
4341
template <class _ValTy, class _Key, class _ContainerValueTy, class _RawValTy = __remove_const_ref_t<_ValTy> >
44-
struct __can_extract_map_key : integral_constant<bool, _IsSame<_RawValTy, _Key>::value> {};
42+
struct __can_extract_map_key : integral_constant<bool, __is_same(_RawValTy, _Key)> {};
4543

4644
// This specialization returns __extract_key_fail_tag for non-map containers
4745
// because _Key == _ContainerValueTy

libcxx/include/__type_traits/common_reference.h

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
#include <__type_traits/common_type.h>
1414
#include <__type_traits/copy_cv.h>
1515
#include <__type_traits/copy_cvref.h>
16-
#include <__type_traits/is_convertible.h>
17-
#include <__type_traits/is_reference.h>
18-
#include <__type_traits/remove_cv.h>
19-
#include <__type_traits/remove_cvref.h>
2016
#include <__type_traits/remove_reference.h>
2117
#include <__utility/declval.h>
2218

@@ -59,7 +55,7 @@ using __cv_cond_res = __cond_res<__copy_cv_t<_Xp, _Yp>&, __copy_cv_t<_Yp, _Xp>&>
5955
template <class _Ap, class _Bp, class _Xp, class _Yp>
6056
requires
6157
requires { typename __cv_cond_res<_Xp, _Yp>; } &&
62-
is_reference_v<__cv_cond_res<_Xp, _Yp>>
58+
__is_reference(__cv_cond_res<_Xp, _Yp>)
6359
struct __common_ref<_Ap&, _Bp&, _Xp, _Yp> {
6460
using __type = __cv_cond_res<_Xp, _Yp>;
6561
};
@@ -75,8 +71,8 @@ using __common_ref_C = remove_reference_t<__common_ref_t<_Xp&, _Yp&>>&&;
7571
template <class _Ap, class _Bp, class _Xp, class _Yp>
7672
requires
7773
requires { typename __common_ref_C<_Xp, _Yp>; } &&
78-
is_convertible_v<_Ap&&, __common_ref_C<_Xp, _Yp>> &&
79-
is_convertible_v<_Bp&&, __common_ref_C<_Xp, _Yp>>
74+
__is_convertible(_Ap&&, __common_ref_C<_Xp, _Yp>) &&
75+
__is_convertible(_Bp&&, __common_ref_C<_Xp, _Yp>)
8076
struct __common_ref<_Ap&&, _Bp&&, _Xp, _Yp> {
8177
using __type = __common_ref_C<_Xp, _Yp>;
8278
};
@@ -92,7 +88,7 @@ using __common_ref_D = __common_ref_t<const _Tp&, _Up&>;
9288
template <class _Ap, class _Bp, class _Xp, class _Yp>
9389
requires
9490
requires { typename __common_ref_D<_Xp, _Yp>; } &&
95-
is_convertible_v<_Ap&&, __common_ref_D<_Xp, _Yp>>
91+
__is_convertible(_Ap&&, __common_ref_D<_Xp, _Yp>)
9692
struct __common_ref<_Ap&&, _Bp&, _Xp, _Yp> {
9793
using __type = __common_ref_D<_Xp, _Yp>;
9894
};
@@ -139,7 +135,7 @@ template <class _Tp, class _Up>
139135
struct common_reference<_Tp, _Up> : __common_reference_sub_bullet1<_Tp, _Up> {};
140136

141137
template <class _Tp, class _Up>
142-
requires is_reference_v<_Tp> && is_reference_v<_Up> && requires { typename __common_ref_t<_Tp, _Up>; }
138+
requires(__is_reference(_Tp) && __is_reference(_Up) && requires { typename __common_ref_t<_Tp, _Up>; })
143139
struct __common_reference_sub_bullet1<_Tp, _Up> {
144140
using type = __common_ref_t<_Tp, _Up>;
145141
};
@@ -151,8 +147,8 @@ struct basic_common_reference {};
151147

152148
template <class _Tp, class _Up>
153149
using __basic_common_reference_t =
154-
typename basic_common_reference<remove_cvref_t<_Tp>,
155-
remove_cvref_t<_Up>,
150+
typename basic_common_reference<__remove_cvref(_Tp),
151+
__remove_cvref(_Up),
156152
__xref<_Tp>::template __apply,
157153
__xref<_Up>::template __apply>::type;
158154

0 commit comments

Comments
 (0)