What is gsl :: multi_span used for?

The C ++ basic guidelines mention spans, not "multiple spans." But - I see that the Microsoft GSL implementation has a classmulti_span

template <
    typename ValueType,
    std::ptrdiff_t FirstDimension,
    std::ptrdiff_t... RestDimensions
>
class multi_span { ... };

So, obviously, this is a kind of multi-dimensional version gsl::span. But what does this have to mean? Why do we need this multidimensional gap, or rather, when will we use it? I can not find documentation on this.

+6
source share
1 answer

In short, this is a space in the adjacent part of the memory representing a multidimensional array.

Here is a usage example:

int data[6] = {0, 1, 2, 3, 4, 5};
multi_span<int, 2, 3> span{data, 6};
std::cout << span[1][1] << '\n'; //Outputs 4

, , .

+5

Source: https://habr.com/ru/post/1681831/


All Articles