add_cv

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 and volatile qualifiers 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_cv;

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 types qualified with const, volatile, or both const and volatile

Restrictions

None

Returns

add_cv is a struct that provides a nested type, which represents the type after the const and volatile qualifiers are added. This type can be accessed through add_cv<Tp>::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
26
27
28
// Test non-const and non-volatile type
ascendc_assert((AscendC::Std::is_same_v<AscendC::Std::add_cv<int>::type, const volatile int>));
ascendc_assert((AscendC::Std::is_same_v<AscendC::Std::add_cv<double>::type, const volatile double>));
ascendc_assert((AscendC::Std::is_same_v<AscendC::Std::add_cv<char>::type, const volatile char>));
// Test const type
ascendc_assert((AscendC::Std::is_same_v<AscendC::Std::add_cv<const int>::type, const volatile int>));
ascendc_assert((AscendC::Std::is_same_v<AscendC::Std::add_cv<const double>::type, const volatile double>));
ascendc_assert((AscendC::Std::is_same_v<AscendC::Std::add_cv<const char>::type, const volatile char>));
// Test volatile type
ascendc_assert((AscendC::Std::is_same_v<AscendC::Std::add_cv<volatile int>::type, const volatile int>));
ascendc_assert((AscendC::Std::is_same_v<AscendC::Std::add_cv<volatile double>::type, const volatile double>));
ascendc_assert((AscendC::Std::is_same_v<AscendC::Std::add_cv<volatile char>::type, const volatile char>));
// Test const and volatile type
ascendc_assert((AscendC::Std::is_same_v<AscendC::Std::add_cv<const volatile int>::type, const volatile int>));
ascendc_assert((AscendC::Std::is_same_v<AscendC::Std::add_cv<const volatile double>::type, const volatile double>));
ascendc_assert((AscendC::Std::is_same_v<AscendC::Std::add_cv<const volatile char>::type, const volatile char>));

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

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

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

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