What if objects with virtual methods were replaced with union/variant?
VTK-m has been struggling with polymorphic types for some time now. Skipping some history and other alternatives (see #381 (closed) for details), it has been suggested to use multiplexing instead of virtual methods.
The idea is that instead of creating a class like
ArrayHandleVirtual that redirects to another
ArrayHandle through virtual methods, we create an
ArrayHandleMultiplex type that contains a
union (or more likely something similar to
boost::variant) that contains an instance of one of some number of complex types.
The downside to this approach is that we will still be limited to some set of known types. That is unavoidable if we are using types that have to be known at compile time. However, because we can multiplex to object at the time of a method call, then we can avoid the combinatorial explosions that we have otherwise run into. It also gives us an opportunity to push all of the implementation into a library so that it does not have to be compiled multiple times.
Although somewhat orthogonal to this issue, I also propose limiting the value type for a particular field to a single type (such as
FloatDefault), selectable by a filter's policy. Filter types that do not fit in the selected field type would have to be copied to an array of the correct type, which is unfortunate. However, most systems pick some sort of precision to work with (e.g. VTK works with
double), and we could support compile flags to best match the type to the data source.