add_const

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product/Atlas A3 inference product

Atlas A2 training product/Atlas A2 inference product

Atlas 200I/500 A2 inference product

x

Atlas inference product AI Core

x

Atlas inference product Vector Core

x

Atlas training product

x

Function Usage

Adds the const qualifier to a specified type during program compilation. This API can be used for type conversion during compilation.

Prototype

1
2
template <typename Tp>
struct add_const;

Parameters

Table 1 Template parameters

Parameter

Description

Tp

Types to be processed, 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

add_const is a struct that provides a nested type, which represents the type after the const qualifier is added. This type can be accessed through add_const<Tp>::type.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
// Test non-const type
ascendc_assert((AscendC::Std::is_same_v<AscendC::Std::add_const<int>::type, const int>));
ascendc_assert((AscendC::Std::is_same_v<AscendC::Std::add_const<double>::type, const double>));
ascendc_assert((AscendC::Std::is_same_v<AscendC::Std::add_const<char>::type, const char>));
// Test const type
ascendc_assert((AscendC::Std::is_same_v<AscendC::Std::add_const<const int>::type, const int>));
ascendc_assert((AscendC::Std::is_same_v<AscendC::Std::add_const<const double>::type, const double>));
ascendc_assert((AscendC::Std::is_same_v<AscendC::Std::add_const<const char>::type, const char>));

ascendc_assert((AscendC::Std::is_same_v<AscendC::Std::add_const_t<int>, const int>));
ascendc_assert((AscendC::Std::is_same_v<AscendC::Std::add_const_t<double>, const double>));

ascendc_assert((AscendC::Std::is_same_v<AscendC::Std::add_const_t<const int>, const int>));
ascendc_assert((AscendC::Std::is_same_v<AscendC::Std::add_const_t<const double>, const double>));