CANN/Ascend C指针类型检测
2026/7/27 6:33:01 网站建设 项目流程

is_pointer

【免费下载链接】asc-devkit本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言,原生支持C和C++标准规范,主要由类库和语言扩展层构成,提供多层级API,满足多维场景算子开发诉求。项目地址: https://gitcode.com/cann/asc-devkit

产品支持情况

  • Ascend 950PR/Ascend 950DT:支持
  • Atlas A3 训练系列产品/Atlas A3 推理系列产品:支持
  • Atlas A2 训练系列产品/Atlas A2 推理系列产品:支持
  • Atlas 200I/500 A2 推理产品:不支持
  • Atlas 推理系列产品AI Core:不支持
  • Atlas 推理系列产品Vector Core:不支持
  • Atlas 训练系列产品:不支持

功能说明

在程序编译时,判断一个类型是否为指针类型,可以用于在编译时进行类型检查和条件处理。

函数原型

template <typename Tp> struct is_pointer;

参数说明

表1模板参数说明

参数名含义
Tp需要检测的类型,包括基本类型(如int、float等)、复合类型(如数组、函数类型)、用户自定义类型(如类、结构体等),以及指针类型本身。

约束说明

返回值说明

is_pointer的静态常量成员value用于获取返回的布尔值,is_pointer<Tp>::value取值如下:

  • true:Tp是指针类型。
  • false:Tp不是指针类型。

调用示例

// 自定义测试类型 struct MyStruct{int val;}; // 函数类型 using FuncType = void(int); // Legitimate pointer types AscendC::printf("AscendC::Std::is_pointer::value:%d\n", AscendC::Std::is_pointer<int*>::value); AscendC::printf("AscendC::Std::is_pointer::value:%d\n", AscendC::Std::is_pointer<char**>::value); AscendC::printf("AscendC::Std::is_pointer::value:%d\n", AscendC::Std::is_pointer<void*>::value); AscendC::printf("AscendC::Std::is_pointer::value:%d\n", AscendC::Std::is_pointer<MyStruct*>::value); AscendC::printf("AscendC::Std::is_pointer::value:%d\n", AscendC::Std::is_pointer<int(*)[5]>::value); AscendC::printf("AscendC::Std::is_pointer::value:%d\n", AscendC::Std::is_pointer<void(*)(int)>::value); // Pointer types limited by CV AscendC::printf("AscendC::Std::is_pointer::value:%d\n", AscendC::Std::is_pointer<const int*>::value); AscendC::printf("AscendC::Std::is_pointer::value:%d\n", AscendC::Std::is_pointer<int* const>::value); AscendC::printf("AscendC::Std::is_pointer::value:%d\n", AscendC::Std::is_pointer<volatile char*>::value); // non-pointer types AscendC::printf("AscendC::Std::is_pointer::value:%d\n", AscendC::Std::is_pointer<int>::value); AscendC::printf("AscendC::Std::is_pointer::value:%d\n", AscendC::Std::is_pointer<int&>::value); AscendC::printf("AscendC::Std::is_pointer::value:%d\n", AscendC::Std::is_pointer<int[5]>::value); AscendC::printf("AscendC::Std::is_pointer::value:%d\n", AscendC::Std::is_pointer<double>::value); AscendC::printf("AscendC::Std::is_pointer::value:%d\n", AscendC::Std::is_pointer<MyStruct>::value); AscendC::printf("AscendC::Std::is_pointer::value:%d\n", AscendC::Std::is_pointer<FuncType>::value); AscendC::printf("AscendC::Std::is_pointer::value:%d\n", AscendC::Std::is_pointer<void>::value);
// 执行结果: AscendC::Std::is_pointer::value:1 AscendC::Std::is_pointer::value:1 AscendC::Std::is_pointer::value:1 AscendC::Std::is_pointer::value:1 AscendC::Std::is_pointer::value:1 AscendC::Std::is_pointer::value:1 AscendC::Std::is_pointer::value:1 AscendC::Std::is_pointer::value:1 AscendC::Std::is_pointer::value:1 AscendC::Std::is_pointer::value:0 AscendC::Std::is_pointer::value:0 AscendC::Std::is_pointer::value:0 AscendC::Std::is_pointer::value:0 AscendC::Std::is_pointer::value:0 AscendC::Std::is_pointer::value:0 AscendC::Std::is_pointer::value:0

【免费下载链接】asc-devkit本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言,原生支持C和C++标准规范,主要由类库和语言扩展层构成,提供多层级API,满足多维场景算子开发诉求。项目地址: https://gitcode.com/cann/asc-devkit

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询