8 ms·
Interesting - is there a type safe way to do this? vector<variant<>>? and/or a custom “vector allocator” to hide the details?
by neeeeees 3y ago
Interesting - is there a type safe way to do this? vector<variant<>>? and/or a custom “vector allocator” to hide the details?
- CyberDildonics 3y agoWhy would you need a variant? If you have one of something, put it on the stack. If you have a lot of the a type, put them in a vector.
- emi2k01 3y agoIsn't that an arena allocator at that point?
- markisus 3y agoIn my example, the T is one specific type. So you could have std::vector<Cat>. If you also have Dogs, you just make another vector std::vector<Dog>. It works fine with the standard allocator. You don't have to do anything special.
- neeeeees 3y agoAh okay that makes sense to me
- noduerme 3y agoIf you wanted a factory that allocated vectors of a variety of known types, you'd probably declare template <typename T> before the generator function, so that on compilation a separate version of that function would be emitted for each type you passed to it. (Not really a c++ expert, but that's my understanding; someone more knowledgeable can correct me).
- pagghiu 3y agoYou can do a Vector<TaggedUnion<Union>>. https://pagghiu.github.io/SaneCppLibraries/library_foundation.html#autotoc_md133 https://pagghiu.github.io/SaneCppLibraries/library_foundatio... I have not been working (yet) on custom allocators, but that's on the roadmap: https://pagghiu.github.io/SaneCppLibraries/library_containers.html#autotoc_md90 https://pagghiu.github.io/SaneCppLibraries/library_container...