购物网站项目简介,百度链接提交入口,为国外客户做网站建设,一键免费搭建手机网站类型特性 类型特性定义一个编译时基于模板的结构#xff0c;以查询或修改类型的属性。 试图特化定义于 type_traits 头文件的模板导致未定义行为#xff0c;除了 std::common_type 可依照其所描述特化。 定义于type_traits头文件的模板可以用不完整类型实例化…类型特性 类型特性定义一个编译时基于模板的结构以查询或修改类型的属性。 试图特化定义于 type_traits 头文件的模板导致未定义行为除了 std::common_type 可依照其所描述特化。 定义于type_traits头文件的模板可以用不完整类型实例化除非另外有指定尽管通常禁止以不完整类型实例化标准库模板。 类型修改 类型修改模板通过应用修改到模板参数创建新类型定义。结果类型可以通过成员 typedef type 访问。 移除给定类型的一层指针
std::remove_pointer template class T struct remove_pointer; (C11 起)
提供成员 typedef type 其为 T 所指向的类型或若 T 不是指针则 type 与 T 相同。
成员类型
名称定义typeT 所指向的类型或若 T 不是指针则为 T
辅助类型 template class T using remove_pointer_t typename remove_pointerT::type; (C14 起)
可能的实现
template class T struct remove_pointer {typedef T type;};
template class T struct remove_pointerT* {typedef T type;};
template class T struct remove_pointerT* const {typedef T type;};
template class T struct remove_pointerT* volatile {typedef T type;};
template class T struct remove_pointerT* const volatile {typedef T type;}; 调用示例
#include iostream
#include type_traitsint main()
{std::cout std::boolalpha;std::cout std::is_sameint, int(): std::is_sameint, int() std::endl;std::cout std::is_sameint, int*(): std::is_sameint, int*() std::endl;std::cout std::is_sameint, int**(): std::is_sameint, int**() std::endl;std::cout ---------------------------------------------------------------------- std::endl;std::cout std::is_sameint, std::remove_pointerint::type(): std::is_sameint, std::remove_pointerint::type() std::endl;std::cout std::is_sameint, std::remove_pointerint*::type(): std::is_sameint, std::remove_pointerint*::type() std::endl;std::cout std::is_sameint, std::remove_pointerint**::type(): std::is_sameint, std::remove_pointerint**::type() std::endl;std::cout ---------------------------------------------------------------------- std::endl;std::cout std::is_sameint, std::remove_pointerint* const::type(): std::is_sameint, std::remove_pointerint* const::type() std::endl;std::cout std::is_sameint, std::remove_pointerint* volatile::type(): std::is_sameint, std::remove_pointerint* volatile::type() std::endl;std::cout std::is_sameint, std::remove_pointerint* const volatile::type(): std::is_sameint, std::remove_pointerint* const volatile::type() std::endl;return 0;
}输出
std::is_sameint, int(): true
std::is_sameint, int*(): false
std::is_sameint, int**(): false
----------------------------------------------------------------------
std::is_sameint, std::remove_pointerint::type(): true
std::is_sameint, std::remove_pointerint*::type(): true
std::is_sameint, std::remove_pointerint**::type(): false
----------------------------------------------------------------------
std::is_sameint, std::remove_pointerint* const::type(): true
std::is_sameint, std::remove_pointerint* volatile::type(): true
std::is_sameint, std::remove_pointerint* const volatile::type(): true