英文:
std::remove_reference_t<std::remove_cv_t<T>> does the order matter?
问题
以下是翻译好的部分:
"在以下情况下,应用的顺序是否重要?"
std::remove_reference_t<std::remove_cv_t<T>>
或
std::remove_cv_t<std::remove_reference_t<T>>
在什么情况下,如果有的话,顺序是否重要?
英文:
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 ?
答案1
得分: 8
有些情况下,这两个类型特征会产生不同的结果。例如,让我们考虑 T = const int&。
-
std::remove_cv_t将移除顶层的 cv 限定符,将const int&转换为const int&,因为没有顶层的 cv 限定符。然后,std::remove_reference_t将返回const int。 -
在第二种情况下,
std::remove_reference_t将返回const int,而std::remove_cv_t将其转换为int。
英文:
There are cases when these two type traits produce different results. For example, let's consider T = const int&.
-
std::remove_cv_twill remove top-level cv-qualifier, turningconst int&intoconst int&, because there is no top-level cv-qualifier.std::remove_reference_twill then returnconst int. -
In the second case,
std::remove_reference_twill returnconst int, andstd::remove_cv_twill transform it intoint.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论