Dispatch1 can be used to dispatch a generic invocation to a non-generic function based on the runtime (reified) type of the first argument. You have to put the non-generic functions in a class (typically you'll only have a single function template which covers all cases, but you may also use several overloaded functions), and they have to be named Do:
Then if you have a ArrayInterface<Generic>
, you can dispatch to the matching template instantiation by writing
This would dispatch the types Int, Float and Vector, for all other types an error will be returned.
If you want to dispatch based on the second argument, use Dispatch2. You can also nest Dispatch2 within Dispatch1 for a double-dispatch as in
This would allow all combinations of Int and Float. Note that for a large number of combinations, the compiler has to create a lot of code.
ALGORITHM | The algorithm to invoke. The class has to contain a function template and/or overloaded functions named Do . These functions will be invoked based on the reified type of the generic argument. |
TYPES | List of types which shall be supported of the form std::tuple<TYPE1, TYPE2, ...> . If the runtime type doesn't match one of these types, an error is returned. |
REIFICATION | The reification class is used to obtain the runtime DataType from the generic argument. It has to contain a GetType function for this purpose, and also a function template which converts the generic argument into the reified argument. By default, DefaultReification is used which supports Data, ArrayInterface and WritableArrayInterface. |