On 9. Apr 2021, at 14:13, Ivica B via Boost
wrote: I am doing a performance C++ work and there is a data structure that we use and I think it is very useful even for the general public. Here is the description:
Currently, I call it *multivector* (I know there is a data structure with the same name, this is a temporary name). It works like this:
You specify all the types you want to hold in your multivector:
multivector
mvect; Each type is held in a separate std::vector for that type. So in the above case, multivector
consists of three std::vectors: std::vector<rectangle>, std::vector<circle> and std::vector<triangle>. Now, the magic happens when we use templates to process all three vectors at once. Imagine there is a function *draw* for all three types. We can do something like this:
mvect.for_each([&](auto& shape) { shape.draw(bitmap); });
The above code generates three for_each loops, for rectangle, circle and triangle. Inside the loops it calls the draw method for each type. There is no dispatching inside the loops, and the loops are really easy for the compiler to optimize (due to their simplicity).
It also sounds like https://www.plflib.org/colony.htm, which is unfortunately not in Boost.