is_reference
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
√ |
|
√ |
|
x |
|
x |
|
x |
|
x |
Function Usage
Checks whether a type is the reference type during program compilation. This API can be used for type checking and conditional processing during compilation.
Prototype
1 2 | template <typename Tp> struct is_reference; |
Parameters
Parameter |
Description |
|---|---|
Tp |
Types to be checked, including basic types (such as int and float), composite types (such as array and pointer), user-defined types (such as class and struct), and the reference type |
Restrictions
None
Returns
The static constant member value of is_reference is used to obtain the returned Boolean value. The values of is_reference<Tp>::value are as follows:
- true: Tp is of the reference type.
- false: Tp is not of the reference type.
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | // Custom test type struct MyStruct{int val;}; // Function type using FuncType = void(int); // Legitimate reference type AscendC::printf("AscendC::Std::is_reference::value:%d\n", AscendC::Std::is_reference<int&>::value); AscendC::printf("AscendC::Std::is_reference::value:%d\n", AscendC::Std::is_reference<int&&>::value); AscendC::printf("AscendC::Std::is_reference::value:%d\n", AscendC::Std::is_reference<int(&)[5]>::value); AscendC::printf("AscendC::Std::is_reference::value:%d\n", AscendC::Std::is_reference<int*&>::value); AscendC::printf("AscendC::Std::is_reference::value:%d\n", AscendC::Std::is_reference<MyStruct&>::value); // CV restricted reference types AscendC::printf("AscendC::Std::is_reference::value:%d\n", AscendC::Std::is_reference<const int&>::value); AscendC::printf("AscendC::Std::is_reference::value:%d\n", AscendC::Std::is_reference<volatile double&&>::value); AscendC::printf("AscendC::Std::is_reference::value:%d\n", AscendC::Std::is_reference<const MyStruct&>::value); // non-reference type AscendC::printf("AscendC::Std::is_reference::value:%d\n", AscendC::Std::is_reference<int>::value); AscendC::printf("AscendC::Std::is_reference::value:%d\n", AscendC::Std::is_reference<int*>::value); AscendC::printf("AscendC::Std::is_reference::value:%d\n", AscendC::Std::is_reference<int[5]>::value); AscendC::printf("AscendC::Std::is_reference::value:%d\n", AscendC::Std::is_reference<double>::value); AscendC::printf("AscendC::Std::is_reference::value:%d\n", AscendC::Std::is_reference<MyStruct>::value); AscendC::printf("AscendC::Std::is_reference::value:%d\n", AscendC::Std::is_reference<FuncType>::value); AscendC::printf("AscendC::Std::is_reference::value:%d\n", AscendC::Std::is_reference<void>::value); |
// Execution result AscendC::Std::is_reference::value:1 AscendC::Std::is_reference::value:1 AscendC::Std::is_reference::value:1 AscendC::Std::is_reference::value:1 AscendC::Std::is_reference::value:1 AscendC::Std::is_reference::value:1 AscendC::Std::is_reference::value:1 AscendC::Std::is_reference::value:1 AscendC::Std::is_reference::value:0 AscendC::Std::is_reference::value:0 AscendC::Std::is_reference::value:0 AscendC::Std::is_reference::value:0 AscendC::Std::is_reference::value:0 AscendC::Std::is_reference::value:0 AscendC::Std::is_reference::value:0