The*_* do 1 c++ metaprogramming
这个:
cout << std::is_const<const int*>::value;
Run Code Online (Sandbox Code Playgroud)
打印错误,我认为它应该打印真实.为什么打印错误?
因为const int *
是一个指向常量整数的变量指针.
std::is_const< int * const >::value
是true
因为类型是一个指向变量整数的常量指针.该const
到任何结合它之前,除非它是第一个在类型说明符.我避免把它放在第一位,以避免调用这个"特殊规则".
常量指针通常由C++中的引用表示.
要获取有关指向的类型的信息,请使用std::remove_pointer
.
std::is_const< typename std::remove_pointer< const int * >::type >::value
Run Code Online (Sandbox Code Playgroud)
是true
.
归档时间: |
|
查看次数: |
178 次 |
最近记录: |