example3_custom_layout.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <vector>
#include <mdspan>

int main() {
    std::vector<int> data = {1, 2, 3, 4, 5, 6, 7, 8, 9};

    // Create a 3x3 mdspan with column-major layout
    std::mdspan<int, std::extents<std::size_t, 3, 3>, std::layout_left> matrix(data.data());

    // Access and print elements
    for (std::size_t i = 0; i < matrix.extent(0); ++i) {
        for (std::size_t j = 0; j < matrix.extent(1); ++j) {
            std::cout << matrix[i, j] << " ";
        }
        std::cout << std::endl;
    }

    return 0;
}
Back to std_mdspan