
Hey, On 00:36 Sun 16 Oct , Michael Marcin wrote:
Indeed this works well for a fixed sized dataset. It doesn't have the wasted duplicated information that a tuple of std::vectors has. It still doesn't provide an interface to query the soa directly for an iterator or size etc.
Both a fixed-sized and dynamic-growth container are useful. Although I tend to need dynamic growth more often.
I've implemented your example using the soa_grid from LibFlatArray: ================================= 8< ============================ #include <libflatarray/flat_array.hpp> class citizen { public: std::string first_name; std::string last_name; int salary; int age; }; LIBFLATARRAY_REGISTER_SOA( citizen, ((std::string)(first_name)) ((std::string)(last_name)) ((int)(salary)) ((int)(age))) int main() { LibFlatArray::soa_grid<citizen> citizens(300, 1, 1); long accumulator = 0; citizens.callback([&citizens, &accumulator](auto i) { for (; i.index() < citizens.dim_x(); ++i) { accumulator += i.salary(); } }); int average = accumulator / citizens.dim_x(); return 0; } ================================= 8< ============================ The size of the soa_grid can be chose at runtime, but it might not be a good match for the use case you describe: it's essentially 3D and hence doesn't support push_back() and friends. On the other hand, LibFlatArray::soa_array is 1D and behaves much more like std::vector, but it also has a maximum size that's fixated at compile time. Would something like an soa_vector, that's resizable at runtime and behaves much like a std::vector better suit your needs? Cheers -Andreas -- ========================================================== Andreas Schäfer HPC and Supercomputing Institute for Multiscale Simulation Friedrich-Alexander-Universität Erlangen-Nürnberg, Germany +49 9131 85-20866 PGP/GPG key via keyserver http://www.libgeodecomp.org ========================================================== (\___/) (+'.'+) (")_(") This is Bunny. Copy and paste Bunny into your signature to help him gain world domination!