Skip to content

Commit 223bd0c

Browse files
authored
[libc++] Avoid unnecessary instantiations for __copy_cvref_t (#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`.
1 parent a77250f commit 223bd0c

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

libcxx/include/__type_traits/copy_cvref.h

+12-9
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,26 @@
2020

2121
_LIBCPP_BEGIN_NAMESPACE_STD
2222

23-
template <class _From, class _To>
23+
template <class _From>
2424
struct __copy_cvref {
25-
using type = __copy_cv_t<_From, _To>;
25+
template <class _To>
26+
using __apply _LIBCPP_NODEBUG = __copy_cv_t<_From, _To>;
2627
};
2728

28-
template <class _From, class _To>
29-
struct __copy_cvref<_From&, _To> {
30-
using type = __add_lvalue_reference_t<__copy_cv_t<_From, _To> >;
29+
template <class _From>
30+
struct __copy_cvref<_From&> {
31+
template <class _To>
32+
using __apply _LIBCPP_NODEBUG = __add_lvalue_reference_t<__copy_cv_t<_From, _To> >;
3133
};
3234

33-
template <class _From, class _To>
34-
struct __copy_cvref<_From&&, _To> {
35-
using type = __add_rvalue_reference_t<__copy_cv_t<_From, _To> >;
35+
template <class _From>
36+
struct __copy_cvref<_From&&> {
37+
template <class _To>
38+
using __apply _LIBCPP_NODEBUG = __add_rvalue_reference_t<__copy_cv_t<_From, _To> >;
3639
};
3740

3841
template <class _From, class _To>
39-
using __copy_cvref_t _LIBCPP_NODEBUG = typename __copy_cvref<_From, _To>::type;
42+
using __copy_cvref_t _LIBCPP_NODEBUG = typename __copy_cvref<_From>::template __apply<_To>;
4043

4144
_LIBCPP_END_NAMESPACE_STD
4245

0 commit comments

Comments
 (0)