Intel® oneAPI DPC++/C++ Compiler Developer Guide and Reference

ID 767253
Date 9/08/2022
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

n_index_generator

To facilitate simpler creation of n_index_t objects, the generator object n_index is provided.

Syntax
template<typename... TypeListT>
class n_index_generator;

namespace { 
    // Instance of generator object
    n_index_generator<> n_index; 
}
Description

The generator object provides recursively constructing operators [] for fixed<>, aligned<>, and integer values allowing building of a n_index_t<…> instance one dimension at a time. Its main purpose is to allow a usage syntax that is similar to C multi-dimensional array definition.

Compare the following examples, instantiating three n_index_t instances, and using the generator object to instantiate equivalent instances.

n_index_t<int, int> idx1(row, col);
n_index_t<int, aligned<16>> idx2(row, aligned<16>(col));
n_index_t<fixed<540>, fixed<960>> idx3(540_fixed, 960_fixed);

auto idx1 = n_index[row][col];
auto idx2 = n_index[row][aligned<16>(col)];
auto idx3 = n_index[540_fixed][960_fixed];

Class Hierarchy

It is expected that n_index_generator < … > not be directly used as a data member or parameter, instead only n_index_t <...> from which it is derived. The generator object n_index can be automatically downcast any place expecting an n_index_t<…> .

The following table provides the template arguments for n_index_generator

Template Argument Description
typename... TypeListT
Comma separated list of types, where the number of types provided controls how many dimensions the generator currently represents. Each type in the list identifies how the size of the corresponding dimension is to be represented. The order of the dimensions is the same order as C++ subscripts declaring a multi-dimensional array – from leftmost to rightmost.

Requirements: Type is int, fixed<NumberT>, or aligned<AlignmentT>.

The following table provides information on the types defined as members of n_index_generator in addition to those inherited from n_index_t.

Member Type Description
typedef n_index_t<TypeListT...> value_type
Type value that the any chained [] operator calls have produced.

The following table provides information on the members of n_index_generator in addition to those inherited from n_index_t

Member Description

n_index_generator ()

Requirements: TypeListT is empty.

Effects: Construct generator with no indices specified.

n_index_generator (const n_index_generator &a_other)

Effects: Construct generator copying any index values from a_other

n_index_generator<TypeListT..., int> operator [] (int a_index) const

Requirements: a_size >= 0.

Returns: n_index_generator<…> with additional rightmost integer based index.

n_index_generator<TypeListT...,
          fixed<NumberT>> operator [] (fixed<NumberT> a_index) const

Requirements: a_size >= 0.

Returns: n_index_generator<…> with additional rightmost fixed<NumberT> index.

n_index_generator<TypeListT...,
          aligned<AlignmentT>> operator [] (aligned<AlignmentT> a_index)

Requirements: a_size >= 0

Returns: n_index_generator<…> with additional rightmost aligned<AlignmentT> based index.

value_type value() const 

Returns: n_extent_t<…> with the correct types and values of the multi-dimensional extents aggregated by the generator.