C++(20):通过remove_cvref_t退化类型

C++(11):通过is_same检查类型,decay退化类型_c++ decay-CSDN博客

介绍了如果通过decay退去类型的修饰符。

C++20提供了更为彻底的类型退化remove_cvref_t,可以去除掉类型的const,引用,以及右值:

#include <type_traits>
#include <iostream>
using namespace std;int main()
{cout<<is_same<std::remove_cvref_t<int>, int>::value<<endl;cout<<is_same<std::remove_cvref_t<const int>, int>::value<<endl;cout<<is_same<std::remove_cvref_t<const int&>, int>::value<<endl;cout<<is_same<std::remove_cvref_t<const int&&>, int>::value<<endl;return 0;
}

运行程序输出:

1

1

1

1