我一直在阅读有关删除type
, here的引用的信息>
我在链接中看到了以下代码
type
#include <iostream> // std::cout #include <type_traits> // std::is_same template<class T1, class T2> void print_is_same() { std::cout << std::is_same<T1, T2>() << '\n'; } int main() { std::cout << std::boolalpha; print_is_same<int, int>(); print_is_same<int, int &>(); print_is_same<int, int &&>(); print_is_same<int, std::remove_reference<int>::type>(); // Why not typename std::remove_reference<int>::type ? print_is_same<int, std::remove_reference<int &>::type>();// Why not typename std::remove_reference<int &>::type ? print_is_same<int, std::remove_reference<int &&>::type>();// Why not typename std::remove_reference<int &&>::type ? }
特性中的type
是从属类型。
可能的实现
std::remove_reference
但是为什么它没有被使用
template< class T > struct remove_reference {typedef T type;}; template< class T > struct remove_reference<T&> {typedef T type;}; template< class T > struct remove_reference<T&&> {typedef T type;};
?
我一直在阅读有关删除该类型的引用的信息,在这里我在链接中包含以下代码#include
typename std::remove_reference</*TYPE*/>::type
特性中的type
是从属类型。
简而言之,您需要std::remove_reference<T>::type
以确保编译器具有以下功能:>
T