is_convertible【免费下载链接】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 推理产品xAtlas 推理系列产品 AI CorexAtlas 推理系列产品 Vector CorexAtlas 训练系列产品x功能说明is_convertible是定义于type_traits头文件的一个类型转换检查工具它提供了一种在程序编译时进行类型转换检查的机制判断两个类型之间是否可以进行隐式转换并返回结果布尔值。本接口可应用在模板元编程、函数重载决议以及静态断言等场景用于在程序编译阶段捕获潜在的类型转换错误避免发生运行时错误。函数原型template typename From, typename To struct is_convertible;参数说明表 1模板参数说明参数名含义From源类型即需要进行转换的原始类型。To目标类型即需要转换到的目标类型。约束说明源类型和目标类型均不支持抽象类和多态类型。返回值说明is_convertible的静态常量成员value用于获取返回的布尔值is_convertibleFrom, To::value取值如下trueFrom类型的对象可以隐式转换为To类型。falseFrom类型的对象不能隐式转换为To类型。调用示例class Base {}; class Derived : public Base {}; class Unrelated {}; // 检查 int 是否可以隐式转换为 double AscendC::PRINTF(Is int convertible to double? %d\n, AscendC::Std::is_convertibleint, double::value); // 检查 double 是否可以隐式转换为 int AscendC::PRINTF(Is double convertible to int? %d\n, AscendC::Std::is_convertibledouble, int::value); // 检查 Derived 是否可以转换为 Base AscendC::PRINTF(Is Derived callable with Base? %d\n, AscendC::Std::is_convertibleDerived, Base::value); // 检查 Base 是否可以转换为 Derived AscendC::PRINTF(Is Base callable with Derived? %d\n, AscendC::Std::is_convertibleBase, Derived::value); // 检查 Derived 是否可以转换为 Unrelated AscendC::PRINTF(Is Derived callable with Unrelated? %d\n, AscendC::Std::is_convertibleDerived, Unrelated::value);// 执行结果 Is int convertible to double? 1 Is double convertible to int? 1 Is Derived callable with Base? 1 Is Base callable with Derived? 0 Is Derived callable with Unrelated? 0【免费下载链接】asc-devkit本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言原生支持C和C标准规范主要由类库和语言扩展层构成提供多层级API满足多维场景算子开发诉求。项目地址: https://gitcode.com/cann/asc-devkit创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
CANN/asc-devkit类型转换检查
is_convertible【免费下载链接】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 推理产品xAtlas 推理系列产品 AI CorexAtlas 推理系列产品 Vector CorexAtlas 训练系列产品x功能说明is_convertible是定义于type_traits头文件的一个类型转换检查工具它提供了一种在程序编译时进行类型转换检查的机制判断两个类型之间是否可以进行隐式转换并返回结果布尔值。本接口可应用在模板元编程、函数重载决议以及静态断言等场景用于在程序编译阶段捕获潜在的类型转换错误避免发生运行时错误。函数原型template typename From, typename To struct is_convertible;参数说明表 1模板参数说明参数名含义From源类型即需要进行转换的原始类型。To目标类型即需要转换到的目标类型。约束说明源类型和目标类型均不支持抽象类和多态类型。返回值说明is_convertible的静态常量成员value用于获取返回的布尔值is_convertibleFrom, To::value取值如下trueFrom类型的对象可以隐式转换为To类型。falseFrom类型的对象不能隐式转换为To类型。调用示例class Base {}; class Derived : public Base {}; class Unrelated {}; // 检查 int 是否可以隐式转换为 double AscendC::PRINTF(Is int convertible to double? %d\n, AscendC::Std::is_convertibleint, double::value); // 检查 double 是否可以隐式转换为 int AscendC::PRINTF(Is double convertible to int? %d\n, AscendC::Std::is_convertibledouble, int::value); // 检查 Derived 是否可以转换为 Base AscendC::PRINTF(Is Derived callable with Base? %d\n, AscendC::Std::is_convertibleDerived, Base::value); // 检查 Base 是否可以转换为 Derived AscendC::PRINTF(Is Base callable with Derived? %d\n, AscendC::Std::is_convertibleBase, Derived::value); // 检查 Derived 是否可以转换为 Unrelated AscendC::PRINTF(Is Derived callable with Unrelated? %d\n, AscendC::Std::is_convertibleDerived, Unrelated::value);// 执行结果 Is int convertible to double? 1 Is double convertible to int? 1 Is Derived callable with Base? 1 Is Base callable with Derived? 0 Is Derived callable with Unrelated? 0【免费下载链接】asc-devkit本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言原生支持C和C标准规范主要由类库和语言扩展层构成提供多层级API满足多维场景算子开发诉求。项目地址: https://gitcode.com/cann/asc-devkit创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考