Skip to content

Commit 7227ec9

Browse files
authored
[libc++][NFC] Remove uses of add_{const,cv,volatile} (#85635)
These traits can be expressed without having to instantiate any classes, reducing compile times slightly.
1 parent d93cfd8 commit 7227ec9

File tree

9 files changed

+20
-37
lines changed

9 files changed

+20
-37
lines changed

libcxx/include/__iterator/iterator_traits.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <__fwd/pair.h>
2222
#include <__iterator/incrementable_traits.h>
2323
#include <__iterator/readable_traits.h>
24-
#include <__type_traits/add_const.h>
2524
#include <__type_traits/common_reference.h>
2625
#include <__type_traits/conditional.h>
2726
#include <__type_traits/disjunction.h>
@@ -493,8 +492,8 @@ using __iter_mapped_type = typename iterator_traits<_InputIterator>::value_type:
493492

494493
template <class _InputIterator>
495494
using __iter_to_alloc_type =
496-
pair< typename add_const<typename iterator_traits<_InputIterator>::value_type::first_type>::type,
497-
typename iterator_traits<_InputIterator>::value_type::second_type>;
495+
pair<const typename iterator_traits<_InputIterator>::value_type::first_type,
496+
typename iterator_traits<_InputIterator>::value_type::second_type>;
498497

499498
template <class _Iter>
500499
using __iterator_category_type = typename iterator_traits<_Iter>::iterator_category;

libcxx/include/__iterator/ranges_iterator_traits.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <__config>
1414
#include <__fwd/pair.h>
1515
#include <__ranges/concepts.h>
16-
#include <__type_traits/add_const.h>
1716
#include <__type_traits/remove_const.h>
1817

1918
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -32,8 +31,7 @@ using __range_mapped_type = typename ranges::range_value_t<_Range>::second_type;
3231

3332
template <ranges::input_range _Range>
3433
using __range_to_alloc_type =
35-
pair<add_const_t<typename ranges::range_value_t<_Range>::first_type>,
36-
typename ranges::range_value_t<_Range>::second_type>;
34+
pair<const typename ranges::range_value_t<_Range>::first_type, typename ranges::range_value_t<_Range>::second_type>;
3735

3836
#endif
3937

libcxx/include/__tuple/tuple_element.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
#include <__config>
1313
#include <__tuple/tuple_indices.h>
1414
#include <__tuple/tuple_types.h>
15-
#include <__type_traits/add_const.h>
16-
#include <__type_traits/add_cv.h>
17-
#include <__type_traits/add_volatile.h>
1815
#include <cstddef>
1916

2017
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -28,17 +25,17 @@ struct _LIBCPP_TEMPLATE_VIS tuple_element;
2825

2926
template <size_t _Ip, class _Tp>
3027
struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const _Tp> {
31-
typedef _LIBCPP_NODEBUG typename add_const<typename tuple_element<_Ip, _Tp>::type>::type type;
28+
typedef _LIBCPP_NODEBUG const typename tuple_element<_Ip, _Tp>::type type;
3229
};
3330

3431
template <size_t _Ip, class _Tp>
3532
struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, volatile _Tp> {
36-
typedef _LIBCPP_NODEBUG typename add_volatile<typename tuple_element<_Ip, _Tp>::type>::type type;
33+
typedef _LIBCPP_NODEBUG volatile typename tuple_element<_Ip, _Tp>::type type;
3734
};
3835

3936
template <size_t _Ip, class _Tp>
4037
struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const volatile _Tp> {
41-
typedef _LIBCPP_NODEBUG typename add_cv<typename tuple_element<_Ip, _Tp>::type>::type type;
38+
typedef _LIBCPP_NODEBUG const volatile typename tuple_element<_Ip, _Tp>::type type;
4239
};
4340

4441
#ifndef _LIBCPP_CXX03_LANG

libcxx/include/__type_traits/copy_cv.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
#define _LIBCPP___TYPE_TRAITS_COPY_CV_H
1111

1212
#include <__config>
13-
#include <__type_traits/add_const.h>
14-
#include <__type_traits/add_cv.h>
15-
#include <__type_traits/add_volatile.h>
1613

1714
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1815
# pragma GCC system_header
@@ -29,17 +26,17 @@ struct __copy_cv {
2926

3027
template <class _From, class _To>
3128
struct __copy_cv<const _From, _To> {
32-
using type = typename add_const<_To>::type;
29+
using type = const _To;
3330
};
3431

3532
template <class _From, class _To>
3633
struct __copy_cv<volatile _From, _To> {
37-
using type = typename add_volatile<_To>::type;
34+
using type = volatile _To;
3835
};
3936

4037
template <class _From, class _To>
4138
struct __copy_cv<const volatile _From, _To> {
42-
using type = typename add_cv<_To>::type;
39+
using type = const volatile _To;
4340
};
4441

4542
template <class _From, class _To>

libcxx/include/__type_traits/is_assignable.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#define _LIBCPP___TYPE_TRAITS_IS_ASSIGNABLE_H
1111

1212
#include <__config>
13-
#include <__type_traits/add_const.h>
1413
#include <__type_traits/add_lvalue_reference.h>
1514
#include <__type_traits/add_rvalue_reference.h>
1615
#include <__type_traits/integral_constant.h>
@@ -31,9 +30,8 @@ inline constexpr bool is_assignable_v = __is_assignable(_Tp, _Arg);
3130

3231
template <class _Tp>
3332
struct _LIBCPP_TEMPLATE_VIS is_copy_assignable
34-
: public integral_constant<
35-
bool,
36-
__is_assignable(__add_lvalue_reference_t<_Tp>, __add_lvalue_reference_t<typename add_const<_Tp>::type>)> {};
33+
: public integral_constant<bool,
34+
__is_assignable(__add_lvalue_reference_t<_Tp>, __add_lvalue_reference_t<const _Tp>)> {};
3735

3836
#if _LIBCPP_STD_VER >= 17
3937
template <class _Tp>

libcxx/include/__type_traits/is_constructible.h

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

1212
#include <__config>
13-
#include <__type_traits/add_const.h>
1413
#include <__type_traits/add_lvalue_reference.h>
1514
#include <__type_traits/add_rvalue_reference.h>
1615
#include <__type_traits/integral_constant.h>
@@ -31,8 +30,7 @@ inline constexpr bool is_constructible_v = __is_constructible(_Tp, _Args...);
3130

3231
template <class _Tp>
3332
struct _LIBCPP_TEMPLATE_VIS is_copy_constructible
34-
: public integral_constant<bool, __is_constructible(_Tp, __add_lvalue_reference_t<typename add_const<_Tp>::type>)> {
35-
};
33+
: public integral_constant<bool, __is_constructible(_Tp, __add_lvalue_reference_t<const _Tp>)> {};
3634

3735
#if _LIBCPP_STD_VER >= 17
3836
template <class _Tp>

libcxx/include/__type_traits/is_nothrow_assignable.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#define _LIBCPP___TYPE_TRAITS_IS_NOTHROW_ASSIGNABLE_H
1111

1212
#include <__config>
13-
#include <__type_traits/add_const.h>
1413
#include <__type_traits/add_lvalue_reference.h>
1514
#include <__type_traits/add_rvalue_reference.h>
1615
#include <__type_traits/integral_constant.h>
@@ -32,9 +31,9 @@ inline constexpr bool is_nothrow_assignable_v = __is_nothrow_assignable(_Tp, _Ar
3231

3332
template <class _Tp>
3433
struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_assignable
35-
: public integral_constant<bool,
36-
__is_nothrow_assignable(__add_lvalue_reference_t<_Tp>,
37-
__add_lvalue_reference_t<typename add_const<_Tp>::type>)> {};
34+
: public integral_constant<
35+
bool,
36+
__is_nothrow_assignable(__add_lvalue_reference_t<_Tp>, __add_lvalue_reference_t<const _Tp>)> {};
3837

3938
#if _LIBCPP_STD_VER >= 17
4039
template <class _Tp>

libcxx/include/__type_traits/is_nothrow_constructible.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#define _LIBCPP___TYPE_TRAITS_IS_NOTHROW_CONSTRUCTIBLE_H
1111

1212
#include <__config>
13-
#include <__type_traits/add_const.h>
1413
#include <__type_traits/add_lvalue_reference.h>
1514
#include <__type_traits/add_rvalue_reference.h>
1615
#include <__type_traits/integral_constant.h>
@@ -74,15 +73,13 @@ inline constexpr bool is_nothrow_constructible_v = is_nothrow_constructible<_Tp,
7473

7574
template <class _Tp>
7675
struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_constructible
77-
: public is_nothrow_constructible<_Tp, __add_lvalue_reference_t<typename add_const<_Tp>::type> > {};
76+
: public is_nothrow_constructible<_Tp, __add_lvalue_reference_t<const _Tp> > {};
7877

7978
#else // _LIBCPP_COMPILER_GCC
8079

8180
template <class _Tp>
8281
struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_constructible
83-
: public integral_constant<
84-
bool,
85-
__is_nothrow_constructible(_Tp, typename add_lvalue_reference<typename add_const<_Tp>::type>::type)> {};
82+
: public integral_constant< bool, __is_nothrow_constructible(_Tp, __add_lvalue_reference_t<const _Tp>)> {};
8683

8784
#endif // _LIBCPP_COMPILER_GCC
8885

libcxx/include/__type_traits/is_trivially_assignable.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ inline constexpr bool is_trivially_assignable_v = __is_trivially_assignable(_Tp,
3131

3232
template <class _Tp>
3333
struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_assignable
34-
: public integral_constant<bool,
35-
__is_trivially_assignable(__add_lvalue_reference_t<_Tp>,
36-
__add_lvalue_reference_t<typename add_const<_Tp>::type>)> {};
34+
: public integral_constant<
35+
bool,
36+
__is_trivially_assignable(__add_lvalue_reference_t<_Tp>, __add_lvalue_reference_t<const _Tp>)> {};
3737

3838
#if _LIBCPP_STD_VER >= 17
3939
template <class _Tp>

0 commit comments

Comments
 (0)