example1_basic_usage.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};
    
    // Create a 2x3 mdspan view over the vector
    std::mdspan<int, std::extents<std::size_t, 2, 3>> 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