
Layout - Example 3
float array[] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f};
std::dims<2> extentsA{2, 3}; // compiler explorer
using layoutA = std::layout_right_padded<std::dynamic_extent>;
layoutA::mapping mappingA{extents, 4};
std::mdspan mdA(array, mappingA);
cout << mdA.stride(0) << ", " << mdA.stride(1) << "\n" // 4, 1
<< mdA.size() << ", " << mappingA.required_span_size() << "\n" // 6, 4 * 2 = 8
<< mdA.is_exhaustive() << " " // false
<< mdA.is_unique() << ", " << mdA.is_strided() << "\n"; // true, true
std::dims<2> extentsB{2, 3};
std::layout_left::mapping mappingB{extentsB};
std::mdspan mdB(array, mappingB);
cout << mdB.stride(0) << ", " << mdB.stride(1) << "\n" // 1, 3
<< mdB.size() << ", " << mappingB.required_span_size() << "\n" // 6, 2 * 3 = 6
<< mdB.is_exhaustive() << " " // true
<< mdB.is_unique() << ", " << mdB.is_strided() << "\n"; // true, true
29/110