I want to make safe and easy adding and removing elements from structure of arrays. Is there a way in modern C++ to do so without writing functions and make these operations explicitly on every array? Separate functions do their work, but with increasing number of arrays code duplication (long list of arrays) becomes more visible and error-prone.
Something like (which, of course, doesn't compile demo; I don't provide error log, since this is just code to show the idea, not code which should work as is)
#include <iostream>
#include <ranges>
#include <vector>
int main()
{
std::vector<float> value;
std::vector<float> threshold;
auto SoA = std::views::zip(value, threshold);
std::fill_n(std::inserter(SoA, SoA.begin()), 1, { 0.0f, 0.0f } );
std::erase(SoA.end());
}
would work for me.
Here I mean that I want to zip somehow vectors in one place and in many other places just use one safe call to change them. Real importance of this will be noticeable when there are many vectors which build the structure and many places where you need add/remove elements.
Useful sources
I found two related implementations:
- Structure of Arrays
- vapid soa
They are comprehensive and well-developed, but the question still on the table if this is possible to implement easier (taking into account my simpler requirements).
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742369482a4430970.html
评论列表(0条)