[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:29:42 PST 2025


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

This changes the implementation of `__copy_cvref_t` to only template the implementation class on the `_From` parameter, avoiding instantiations for every combination of `_From` and `_To`.


>From 0f462f929117c916d9c8100f04a992dbb70c92d0 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..7b57ccb00a7db4 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 = __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 = __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 = __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