[libcxx-commits] [libcxx] [libc++] Avoid unnecessary instantiations for __copy_cvref_t (PR #123718)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jan 21 01:49:58 PST 2025


https://github.com/philnik777 updated https://github.com/llvm/llvm-project/pull/123718

>From d399df88358c6c578ac017ef927d32336358f868 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Tue, 21 Jan 2025 10:28:05 +0100
Subject: [PATCH] [libc++] Avoid unnecessary instantiations for __copy_cvref_t

---
 libcxx/include/__type_traits/copy_cvref.h | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/libcxx/include/__type_traits/copy_cvref.h b/libcxx/include/__type_traits/copy_cvref.h
index 511d4e0776d609..158e5a5d78bb35 100644
--- a/libcxx/include/__type_traits/copy_cvref.h
+++ b/libcxx/include/__type_traits/copy_cvref.h
@@ -20,23 +20,26 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-template <class _From, class _To>
+template <class _From>
 struct __copy_cvref {
-  using type = __copy_cv_t<_From, _To>;
+  template <class _To>
+  using __apply _LIBCPP_NODEBUG = __copy_cv_t<_From, _To>;
 };
 
-template <class _From, class _To>
-struct __copy_cvref<_From&, _To> {
-  using type = __add_lvalue_reference_t<__copy_cv_t<_From, _To> >;
+template <class _From>
+struct __copy_cvref<_From&> {
+  template <class _To>
+  using __apply _LIBCPP_NODEBUG = __add_lvalue_reference_t<__copy_cv_t<_From, _To> >;
 };
 
-template <class _From, class _To>
-struct __copy_cvref<_From&&, _To> {
-  using type = __add_rvalue_reference_t<__copy_cv_t<_From, _To> >;
+template <class _From>
+struct __copy_cvref<_From&&> {
+  template <class _To>
+  using __apply _LIBCPP_NODEBUG = __add_rvalue_reference_t<__copy_cv_t<_From, _To> >;
 };
 
 template <class _From, class _To>
-using __copy_cvref_t _LIBCPP_NODEBUG = typename __copy_cvref<_From, _To>::type;
+using __copy_cvref_t _LIBCPP_NODEBUG = typename __copy_cvref<_From>::template __apply<_To>;
 
 _LIBCPP_END_NAMESPACE_STD
 



More information about the libcxx-commits mailing list