admin管理员组文章数量:1334342
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).
本文标签: cHow to handle elements addingremoving in structure of arraysStack Overflow
版权声明:本文标题:c++ - How to handle elements addingremoving in structure of arrays - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742369481a2461944.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论