Efficient Data Structures

Context

Using std::span

We can now create and manage instances of S with F == std::span. The code below shows of it works. For the implementation of the classes S and wrapper::wrapper, refer to the link to the compiler explorer on Indico.

std::size_t N = 18;

std::vector<int> x(N);
std::vector<int> y(N);
std::vector<Point2D> point(N);
std::vector<std::string> identifier(N);

wrapper::wrapper<std::span, S, wrapper::layout::soa> my_array = {{x, y, point, identifier}};

Factory Functions for Using an Existing Buffer

The code below shows how to use the factory function factory::make_wrapper to create an AOS vs SOA wrapper instance using an existing buffer. For the implementation of the factory function, refer to the link to the compiler explorer on Indico.

constexpr std::size_t bytes = 1024;
char buffer[bytes];
// change "soa" to "aos" in the line below

auto my_array = factory::make_wrapper<S, wrapper::layout::soa>(buffer, bytes);