[libcxx-commits] [libcxx] [libc++][NFC] Use __copy_cv to implement __apply_cv (PR #86477)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Mar 28 10:20:06 PDT 2024
================
@@ -10,64 +10,24 @@
#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
#endif
_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&> {
----------------
ldionne wrote:
An improvement to `__copy_cv_ref_t` we could maybe do is
```c++
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>;
```
https://github.com/llvm/llvm-project/pull/86477
More information about the libcxx-commits
mailing list