A way for a function to accept multiple types of 2d-collections (rectangular matrix) as parameter like 2d-array or array of vectors. 2d-span? mdspan? [closed]

21 hours ago 1
ARTICLE AD BOX

AFAIK, these collections are memory contiguous:

C-style array T[N] Array std::array<T, N> Vector std::vector<T>

And these 2-dimensional collections would also be memory contiguous:

C-style array of arrays (2d array) T[M][N] Array of arrays (2d array) std::array<std::array<T, N>, M>

A vector of vectors (2d vector) std::vector<std::vector<T>> would not be memory contiguous (because each inner vector, rows/sub-vectors, can have different size?)

But what about these 2-dimensional collections?

std::array<std::vector<T>, N> std::vector<<std::array<T, N>>

An example of a work case would be about a function with a parameter that could receive multiple types of 2d-collections, beyond 2d-arrays, being 2d-collections that represent rectangular matrices:

A parameter for 2d-collections equivalent to std::span for 1d collections.

Also ideally with an equivalent simplified function implementation like a function with a std::span parameter for 1d collections (simplified equivalence of something like std::vector<int> func_1(std::span<int> span_1)).

Read Entire Article