Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::remove_reference_t<std::remove_cv_t<T>> does the order matter?

Does it matter in which order the following is applied ?

std::remove_reference_t<std::remove_cv_t<T>>

or

std::remove_cv_t<std::remove_reference_t<T>>

In what scenario, if any, does the order matter ?

like image 595
darune Avatar asked Jan 06 '20 09:01

darune


Video Answer


1 Answers

There are cases when these two type traits produce different results. For example, let's consider T = const int&.

  1. std::remove_cv_t will remove top-level cv-qualifier, turning const int& into const int&, because there is no top-level cv-qualifier. std::remove_reference_t will then return const int.

  2. In the second case, std::remove_reference_t will return const int, and std::remove_cv_t will transform it into int.

Simple demo

like image 166
Evg Avatar answered Nov 16 '22 02:11

Evg