is_const
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
√ |
|
√ |
|
x |
|
x |
|
x |
|
x |
Function Usage
Checks whether a type is the const 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_const; |
Parameters
Parameter |
Description |
|---|---|
Tp |
Types to be checked, including basic types (such as int and float), composite types (such as array, pointer, and reference), user-defined types (such as class and struct), and const-qualified types |
Restrictions
None
Returns
The static constant member value of is_const is used to obtain the returned Boolean value. The values of is_const<Tp>::value are as follows:
- true: Tp is of the const type.
- false: Tp is not of the const type.
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | // Custom test type struct MyStruct{int val;}; // Mismatch scenario AscendC::printf("AscendC::Std::is_const::value:%d\n", AscendC::Std::is_const<int>::value); AscendC::printf("AscendC::Std::is_const::value:%d\n", AscendC::Std::is_const<const int*>::value); AscendC::printf("AscendC::Std::is_const::value:%d\n", AscendC::Std::is_const<int&>::value); AscendC::printf("AscendC::Std::is_const::value:%d\n", AscendC::Std::is_const<const int&>::value); AscendC::printf("AscendC::Std::is_const::value:%d\n", AscendC::Std::is_const<int&&>::value); AscendC::printf("AscendC::Std::is_const::value:%d\n", AscendC::Std::is_const<int[5]>::value); AscendC::printf("AscendC::Std::is_const::value:%d\n", AscendC::Std::is_const<double>::value); AscendC::printf("AscendC::Std::is_const::value:%d\n", AscendC::Std::is_const<MyStruct>::value); AscendC::printf("AscendC::Std::is_const::value:%d\n", AscendC::Std::is_const<void>::value); // Matching scenario AscendC::printf("AscendC::Std::is_const::value:%d\n", AscendC::Std::is_const<const int>::value); AscendC::printf("AscendC::Std::is_const::value:%d\n", AscendC::Std::is_const<int const>::value); AscendC::printf("AscendC::Std::is_const::value:%d\n", AscendC::Std::is_const<int* const>::value); AscendC::printf("AscendC::Std::is_const::value:%d\n", AscendC::Std::is_const<const int[5]>::value); AscendC::printf("AscendC::Std::is_const::value:%d\n", AscendC::Std::is_const<const volatile double>::value); AscendC::printf("AscendC::Std::is_const::value:%d\n", AscendC::Std::is_const<const MyStruct>::value); |
// Execution result AscendC::Std::is_const::value:0 AscendC::Std::is_const::value:0 AscendC::Std::is_const::value:0 AscendC::Std::is_const::value:0 AscendC::Std::is_const::value:0 AscendC::Std::is_const::value:0 AscendC::Std::is_const::value:0 AscendC::Std::is_const::value:0 AscendC::Std::is_const::value:0 AscendC::Std::is_const::value:1 AscendC::Std::is_const::value:1 AscendC::Std::is_const::value:1 AscendC::Std::is_const::value:1 AscendC::Std::is_const::value:1 AscendC::Std::is_const::value:1