Skip to content

[libc++] Avoid unnecessary instantiations for __copy_cvref_t #123718

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
Jan 22, 2025

Conversation

philnik777
Copy link
Contributor

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.

@philnik777 philnik777 marked this pull request as ready for review January 22, 2025 22:33
@philnik777 philnik777 requested a review from a team as a code owner January 22, 2025 22:33
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jan 22, 2025
@philnik777 philnik777 merged commit 223bd0c into llvm:main Jan 22, 2025
84 checks passed
@llvmbot
Copy link
Member

llvmbot commented Jan 22, 2025

@llvm/pr-subscribers-libcxx

Author: Nikolas Klauser (philnik777)

Changes

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.


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

1 Files Affected:

  • (modified) libcxx/include/__type_traits/copy_cvref.h (+12-9)
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
 

@philnik777 philnik777 deleted the optimize_copy_cvref branch March 29, 2025 08:08
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.

2 participants