Skip to content

Commit

Permalink
[libc++][NFC] Replace __apply_cv with __copy_cv or __copy_cvref (#90867)
Browse files Browse the repository at this point in the history
`__apply_cv_t` and `__copy_cvref_t` are very closely related. They are
in fact identical except that `__copy_cvref_t` handles rvalue references
properly. Some uses don't actually require handling of references, so
they are replaced with `__copy_cv_t`.
  • Loading branch information
philnik777 authored May 10, 2024
1 parent af0b293 commit 05f88b1
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 58 deletions.
1 change: 0 additions & 1 deletion libcxx/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,6 @@ set(files
__type_traits/aligned_storage.h
__type_traits/aligned_union.h
__type_traits/alignment_of.h
__type_traits/apply_cv.h
__type_traits/can_extract_key.h
__type_traits/common_reference.h
__type_traits/common_type.h
Expand Down
6 changes: 3 additions & 3 deletions libcxx/include/__tuple/make_tuple_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <__tuple/tuple_indices.h>
#include <__tuple/tuple_size.h>
#include <__tuple/tuple_types.h>
#include <__type_traits/apply_cv.h>
#include <__type_traits/copy_cvref.h>
#include <__type_traits/remove_cv.h>
#include <__type_traits/remove_reference.h>
#include <cstddef>
Expand All @@ -41,15 +41,15 @@ template <template <class...> class _Tuple, class... _Types, size_t... _Idx>
struct __make_tuple_types_flat<_Tuple<_Types...>, __tuple_indices<_Idx...>> {
// Specialization for pair, tuple, and __tuple_types
template <class _Tp>
using __apply_quals _LIBCPP_NODEBUG = __tuple_types<__apply_cv_t<_Tp, __type_pack_element<_Idx, _Types...>>...>;
using __apply_quals _LIBCPP_NODEBUG = __tuple_types<__copy_cvref_t<_Tp, __type_pack_element<_Idx, _Types...>>...>;
};

template <class _Vt, size_t _Np, size_t... _Idx>
struct __make_tuple_types_flat<array<_Vt, _Np>, __tuple_indices<_Idx...>> {
template <size_t>
using __value_type = _Vt;
template <class _Tp>
using __apply_quals = __tuple_types<__apply_cv_t<_Tp, __value_type<_Idx>>...>;
using __apply_quals = __tuple_types<__copy_cvref_t<_Tp, __value_type<_Idx>>...>;
};

template <class _Tp,
Expand Down
38 changes: 0 additions & 38 deletions libcxx/include/__type_traits/apply_cv.h

This file was deleted.

3 changes: 1 addition & 2 deletions libcxx/include/__type_traits/make_signed.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#define _LIBCPP___TYPE_TRAITS_MAKE_SIGNED_H

#include <__config>
#include <__type_traits/apply_cv.h>
#include <__type_traits/is_enum.h>
#include <__type_traits/is_integral.h>
#include <__type_traits/nat.h>
Expand Down Expand Up @@ -70,7 +69,7 @@ template <> struct __make_signed<__uint128_t, true> {typedef __int128_t t
// clang-format on

template <class _Tp>
using __make_signed_t = __apply_cv_t<_Tp, typename __make_signed<__remove_cv_t<_Tp> >::type>;
using __make_signed_t = __copy_cv_t<_Tp, typename __make_signed<__remove_cv_t<_Tp> >::type>;

#endif // __has_builtin(__make_signed)

Expand Down
4 changes: 2 additions & 2 deletions libcxx/include/__type_traits/make_unsigned.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#define _LIBCPP___TYPE_TRAITS_MAKE_UNSIGNED_H

#include <__config>
#include <__type_traits/apply_cv.h>
#include <__type_traits/conditional.h>
#include <__type_traits/copy_cv.h>
#include <__type_traits/is_enum.h>
#include <__type_traits/is_integral.h>
#include <__type_traits/is_unsigned.h>
Expand Down Expand Up @@ -72,7 +72,7 @@ template <> struct __make_unsigned<__uint128_t, true> {typedef __uint128_
// clang-format on

template <class _Tp>
using __make_unsigned_t = __apply_cv_t<_Tp, typename __make_unsigned<__remove_cv_t<_Tp> >::type>;
using __make_unsigned_t = __copy_cv_t<_Tp, typename __make_unsigned<__remove_cv_t<_Tp> >::type>;

#endif // __has_builtin(__make_unsigned)

Expand Down
4 changes: 2 additions & 2 deletions libcxx/include/cwchar
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,
*/

#include <__config>
#include <__type_traits/apply_cv.h>
#include <__type_traits/copy_cv.h>
#include <__type_traits/is_constant_evaluated.h>
#include <__type_traits/is_equality_comparable.h>
#include <__type_traits/is_same.h>
Expand Down Expand Up @@ -236,7 +236,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp* __constexpr_wmemchr(_Tp
wchar_t __value_buffer = 0;
__builtin_memcpy(&__value_buffer, &__value, sizeof(wchar_t));
return reinterpret_cast<_Tp*>(
__builtin_wmemchr(reinterpret_cast<__apply_cv_t<_Tp, wchar_t>*>(__str), __value_buffer, __count));
__builtin_wmemchr(reinterpret_cast<__copy_cv_t<_Tp, wchar_t>*>(__str), __value_buffer, __count));
}
# if _LIBCPP_STD_VER >= 17
else if constexpr (is_same_v<remove_cv_t<_Tp>, wchar_t>)
Expand Down
5 changes: 0 additions & 5 deletions libcxx/include/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -1860,11 +1860,6 @@ module std_private_type_traits_add_volatile [system
module std_private_type_traits_aligned_storage [system] { header "__type_traits/aligned_storage.h" }
module std_private_type_traits_aligned_union [system] { header "__type_traits/aligned_union.h" }
module std_private_type_traits_alignment_of [system] { header "__type_traits/alignment_of.h" }
module std_private_type_traits_apply_cv [system] {
header "__type_traits/apply_cv.h"
export std_private_type_traits_is_const
export std_private_type_traits_is_volatile
}
module std_private_type_traits_can_extract_key [system] { header "__type_traits/can_extract_key.h" }
module std_private_type_traits_common_reference [system] {
header "__type_traits/common_reference.h"
Expand Down
7 changes: 3 additions & 4 deletions libcxx/include/tuple
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ template <class... Types>
#include <__tuple/tuple_like_ext.h>
#include <__tuple/tuple_size.h>
#include <__tuple/tuple_types.h>
#include <__type_traits/apply_cv.h>
#include <__type_traits/common_reference.h>
#include <__type_traits/common_type.h>
#include <__type_traits/conditional.h>
Expand Down Expand Up @@ -1286,14 +1285,14 @@ struct __tuple_cat_return_ref_imp;
template <class... _Types, size_t... _I0, class _Tuple0>
struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0> {
typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tuple0> _T0;
typedef tuple<_Types..., __apply_cv_t<_Tuple0, typename tuple_element<_I0, _T0>::type>&&...> type;
typedef tuple<_Types..., __copy_cvref_t<_Tuple0, typename tuple_element<_I0, _T0>::type>&&...> type;
};

template <class... _Types, size_t... _I0, class _Tuple0, class _Tuple1, class... _Tuples>
struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0, _Tuple1, _Tuples...>
: public __tuple_cat_return_ref_imp<
tuple<_Types...,
__apply_cv_t<_Tuple0, typename tuple_element<_I0, __libcpp_remove_reference_t<_Tuple0>>::type>&&...>,
__copy_cvref_t<_Tuple0, typename tuple_element<_I0, __libcpp_remove_reference_t<_Tuple0>>::type>&&...>,
typename __make_tuple_indices<tuple_size<__libcpp_remove_reference_t<_Tuple1> >::value>::type,
_Tuple1,
_Tuples...> {};
Expand Down Expand Up @@ -1327,7 +1326,7 @@ struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J
(void)__t; // avoid unused parameter warning on GCC when _I0 is empty
typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tuple0> _T0;
typedef _LIBCPP_NODEBUG __libcpp_remove_reference_t<_Tuple1> _T1;
return __tuple_cat<tuple<_Types..., __apply_cv_t<_Tuple0, typename tuple_element<_J0, _T0>::type>&&...>,
return __tuple_cat<tuple<_Types..., __copy_cvref_t<_Tuple0, typename tuple_element<_J0, _T0>::type>&&...>,
typename __make_tuple_indices<sizeof...(_Types) + tuple_size<_T0>::value>::type,
typename __make_tuple_indices<tuple_size<_T1>::value>::type>()(
std::forward_as_tuple(
Expand Down
1 change: 0 additions & 1 deletion libcxx/include/type_traits
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ namespace std
#include <__type_traits/aligned_storage.h>
#include <__type_traits/aligned_union.h>
#include <__type_traits/alignment_of.h>
#include <__type_traits/apply_cv.h>
#include <__type_traits/can_extract_key.h>
#include <__type_traits/common_reference.h>
#include <__type_traits/common_type.h>
Expand Down

0 comments on commit 05f88b1

Please sign in to comment.