-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmdspan.cpp
More file actions
41 lines (33 loc) · 787 Bytes
/
mdspan.cpp
File metadata and controls
41 lines (33 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <mdspan>
#include <span>
#include <iostream>
#include <vector>
int main()
{
std::vector<double> vec{2.4, 4.6, 6.2, -20.0, -5.4, -6.7};
std::cout << "vec : ";
for (auto x : vec)
std::cout << x << " ";
std::cout << "\n";
auto md = std::mdspan(vec.data(),3,2);
std::cout << "md :\n";
for (int i = 0; i < md.extent(0); ++i)
{
for (int j=0; j<md.extent(1); ++j)
{
std::cout << md[i,j] << " ";
}
std::cout << "\n";
}
std::span<double> sp(vec);
std::cout << "\nspan over vec : ";
for (auto x : sp)
std::cout << x << " ";
std::cout << "\n";
auto sub = sp.subspan(2, 3);
std::cout << "subspan (index 2, length 3) : ";
for (auto x : sub)
std::cout << x << " ";
std::cout << "\n";
return EXIT_SUCCESS;
}