The following code example is taken from the book
C++23 - The Complete Guide
by Nicolai M. Josuttis,
Leanpub, 2026
The code is licensed under a
Creative Commons Attribution 4.0 International License.
// raw code
#include <mdspan>
#include "print2d.hpp"
#include "memacc.hpp"
int main()
{
// initialize the accessor holding memory of the necessary size:
std::layout_right::mapping layout{std::extents{4, 3}};
MemoryAccessor<int> acc{layout.required_span_size()};
// initialize an mdspan with the accessor:
std::mdspan mds(acc.dataHandle(), layout, acc);
// print its initial content:
print2D(mds);
}