darune
darune

Reputation: 11150

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 ?

Upvotes: 8

Views: 1352

Answers (1)

Evg
Evg

Reputation: 26362

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

Upvotes: 8

Related Questions