integer_sequence
Applicability
Product |
Supported |
|---|---|
√ |
|
√ |
|
x |
|
√ |
|
x |
|
x |
Function
index_sequence is a class template provided by Ascend C. It is used to generate an integer sequence for building and is applicable to template metaprogramming.
make_index_sequence is a template provided by Ascend C. Generally, make_index_sequence is used to create an object of the index_sequence type to generate an integer sequence from 0 to N-1.
Prototype
1 2 | template<size_t... Idx> using index_sequence = IntegerSequence<size_t, Idx...>; |
1 2 | template<size_t N> using make_index_sequence = MakeIntegerSequence<size_t, N>; |
Parameters
Parameter |
Description |
|---|---|
...Idx |
Formal parameter package of a sequence. size_t (long unsigned int for 64-bit systems and unsigned int for non-64-bit systems) |
N |
Size of the generated integer sequence. size_t (long unsigned int for 64-bit systems and unsigned int for non-64-bit systems) |
Restrictions
- N ranges from 0 to 64.
- index_sequence is a sequence with the maximum length of 64.
Returns
None
Example
Generate and print an integer sequence of length 5.
1 2 3 4 5 6 7 8 9 | template<size_t... Is> __aicore__ inline void PrintIndexSequence(AscendC::Std::index_sequence<Is...>) { ((AscendC::printf(" Is:%lu", Is)), ...); } __aicore__ inline void Process() { PrintIndexSequence(AscendC::Std::make_index_sequence<5>{}); // The print result is 0, 1, 2, 3, or 4. PrintIndexSequence(AscendC::Std::index_sequence<0,1,2,10,8000>{}); // The print result is 0, 1, 2, 10, or 8000. } |