Skip to content

[libc++][NFC] Use __copy_cv to implement __apply_cv #86477

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
Mar 29, 2024

Conversation

philnik777
Copy link
Contributor

No description provided.

Copy link

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link

✅ With the latest revision this PR passed the Python code formatter.

@philnik777 philnik777 marked this pull request as ready for review March 28, 2024 16:59
@philnik777 philnik777 requested a review from a team as a code owner March 28, 2024 16:59
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Mar 28, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 28, 2024

@llvm/pr-subscribers-libcxx

Author: Nikolas Klauser (philnik777)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/86477.diff

1 Files Affected:

  • (modified) libcxx/include/__type_traits/apply_cv.h (+5-45)
diff --git a/libcxx/include/__type_traits/apply_cv.h b/libcxx/include/__type_traits/apply_cv.h
index 7c6aabec8344b1..723af95b8d9280 100644
--- a/libcxx/include/__type_traits/apply_cv.h
+++ b/libcxx/include/__type_traits/apply_cv.h
@@ -10,9 +10,7 @@
 #define _LIBCPP___TYPE_TRAITS_APPLY_CV_H
 
 #include <__config>
-#include <__type_traits/is_const.h>
-#include <__type_traits/is_volatile.h>
-#include <__type_traits/remove_reference.h>
+#include <__type_traits/copy_cv.h>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header
@@ -20,54 +18,16 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-template <class _Tp,
-          bool = is_const<__libcpp_remove_reference_t<_Tp> >::value,
-          bool = is_volatile<__libcpp_remove_reference_t<_Tp> >::value>
-struct __apply_cv_impl {
-  template <class _Up>
-  using __apply _LIBCPP_NODEBUG = _Up;
-};
-
 template <class _Tp>
-struct __apply_cv_impl<_Tp, true, false> {
-  template <class _Up>
-  using __apply _LIBCPP_NODEBUG = const _Up;
-};
-
-template <class _Tp>
-struct __apply_cv_impl<_Tp, false, true> {
-  template <class _Up>
-  using __apply _LIBCPP_NODEBUG = volatile _Up;
-};
-
-template <class _Tp>
-struct __apply_cv_impl<_Tp, true, true> {
-  template <class _Up>
-  using __apply _LIBCPP_NODEBUG = const volatile _Up;
-};
-
-template <class _Tp>
-struct __apply_cv_impl<_Tp&, false, false> {
-  template <class _Up>
-  using __apply _LIBCPP_NODEBUG = _Up&;
-};
-
-template <class _Tp>
-struct __apply_cv_impl<_Tp&, true, false> {
-  template <class _Up>
-  using __apply _LIBCPP_NODEBUG = const _Up&;
-};
-
-template <class _Tp>
-struct __apply_cv_impl<_Tp&, false, true> {
+struct __apply_cv_impl {
   template <class _Up>
-  using __apply _LIBCPP_NODEBUG = volatile _Up&;
+  using __apply _LIBCPP_NODEBUG = __copy_cv_t<_Tp, _Up>;
 };
 
 template <class _Tp>
-struct __apply_cv_impl<_Tp&, true, true> {
+struct __apply_cv_impl<_Tp&> {
   template <class _Up>
-  using __apply _LIBCPP_NODEBUG = const volatile _Up&;
+  using __apply _LIBCPP_NODEBUG = __copy_cv_t<_Tp, _Up>&;
 };
 
 template <class _Tp, class _Up>

};

template <class _Tp>
struct __apply_cv_impl<_Tp&, true, true> {
struct __apply_cv_impl<_Tp&> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An improvement to __copy_cv_ref_t we could maybe do is

template <bool _Ref>
struct __copy_cv_ref_impl;

template <>
struct __copy_cv_ref_impl<true> {
  template <class _Tp>
  using __apply _LIBCPP_NODEBUG = _Tp&;
};

template <>
struct __copy_cv_ref_impl<false> {
  template <class _Tp>
  using __apply _LIBCPP_NODEBUG = _Tp;
};

template <class _Tp>
using __copy_cvref_t = typename __copy_cv_ref_impl<is_lvalue_reference_v<_Tp>>::template __apply<_Tp>;

@philnik777 philnik777 merged commit a855692 into llvm:main Mar 29, 2024
@philnik777 philnik777 deleted the simplify_apply_cv branch March 29, 2024 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants