[Type preserving dynamic heterogeneous containers for C++.]
eumorphic
is a proof of concept implementation of containers that are type agnostic and do not rely on dynamic dispatch.
The design is motivated by the following needs.
- Eliminate coupling between the data types stored in heterogeneous containers.
- Eliminate reference semantics both in the interface and the container backbone.
- Achieve high performance, beyond what polymorphic or type erasure dynamic dispatch can achieve.
The interface that the present concept can provide, is summarized in the following snippet:
struct a { }; void process ( const a& ) { /*...*/ }
struct b { }; void process ( const b& ) { /*...*/ }
struct c { }; void process ( const c& ) { /*...*/ }
template <class T>
using segment_container_t = std::vector<T>;
using collection_t = eumorphic::collection
<
segment_container_t,
a, b, c
>;
//...
collection_t collection;
collection.insert( a{} );
collection.insert( c{} );
collection.insert( b{} );
eumorphic::for_each( collection, []( auto &&elem )
{
process( elem );
} );
It should be noted that we are not trying to address all the use cases polymorphism is dealing with - only the cases relating to dynamic heterogeneous containers.
The development is heavily motivated by modern software design concerns raised in [Parent2013].
As a data structure, eumorphic::collection
is a tuple of arrays of different types. For example:
hana::tuple< std::vector<int>, std::vector<string>, std::vector<MyType> > collection_data;
The rest of the implementation deals with insertion and access operations for unordered (where the user does not care about the iteration order) and ordered collections (where the user expects that the iteration order will be the same with the insertion order).
eumorphic
achieves dynamic heterogeneous containers that observe the following:
- There are no polymorphic types, only a use of similar types.
- Minimal boilerplate.
- Minimal adaptation requirements for existing types.
- Value semantics.
- No coupling.
- Performance - No dynamic dispatch overhead for unordered collections of data.
- Able to be used in non-template functions.
The properties list is a modification of the list in [Bandela2019].
Benchmarks comparing eumorphic with other types, for insertion and basic processing operations follow. Compiled with MSVC 2019 16.2.5.
We developed concepts that demonstrate that dynamic heterogeneous containers do not generally need to rely on dynamic dispatch. Also, we demonstrated that such ideas can provide total decoupling between types and also result in interfaces with extremely low boilerplate requirements. An additional advantage is that decoupled heterogeneous dynamic containers can be constructed on the stack.