Skip to content

Commit b63fe0d

Browse files
authored
[libc++][NFC] Reduce the memory footprint of __copy_cv a bit (#87718)
Instead of instantiating `__copy_cv` for every combination of `_From` and `_To` this only instantiates `__copy_cv` for every `_From` type, reducing the number of instantiations.
1 parent 7ab7e7a commit b63fe0d

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

libcxx/include/__type_traits/copy_cv.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,32 @@ _LIBCPP_BEGIN_NAMESPACE_STD
1919

2020
// Let COPYCV(FROM, TO) be an alias for type TO with the addition of FROM's
2121
// top-level cv-qualifiers.
22-
template <class _From, class _To>
22+
template <class _From>
2323
struct __copy_cv {
24-
using type = _To;
24+
template <class _To>
25+
using __apply = _To;
2526
};
2627

27-
template <class _From, class _To>
28-
struct __copy_cv<const _From, _To> {
29-
using type = const _To;
28+
template <class _From>
29+
struct __copy_cv<const _From> {
30+
template <class _To>
31+
using __apply = const _To;
3032
};
3133

32-
template <class _From, class _To>
33-
struct __copy_cv<volatile _From, _To> {
34-
using type = volatile _To;
34+
template <class _From>
35+
struct __copy_cv<volatile _From> {
36+
template <class _To>
37+
using __apply = volatile _To;
3538
};
3639

37-
template <class _From, class _To>
38-
struct __copy_cv<const volatile _From, _To> {
39-
using type = const volatile _To;
40+
template <class _From>
41+
struct __copy_cv<const volatile _From> {
42+
template <class _To>
43+
using __apply = const volatile _To;
4044
};
4145

4246
template <class _From, class _To>
43-
using __copy_cv_t = typename __copy_cv<_From, _To>::type;
47+
using __copy_cv_t = typename __copy_cv<_From>::template __apply<_To>;
4448

4549
_LIBCPP_END_NAMESPACE_STD
4650

0 commit comments

Comments
 (0)