Instantiating templates where type is known only at run time

bearophile bearophileHUGS at lycos.com
Tue Nov 19 04:53:49 PST 2013


Craig Dillabaugh:

> //  Assume images are of the same dimensions. Result is
> //  saved in Out.
> void add(T,U,V)(Image!T A, Image!U B, Image!V Out) {
>      ...
> }

Take a look at the "out" annotation in D.



> Anyway, thanks to whoever takes the time to read all that, let
> alone come up with an answer.

In D there is no "type switch" but there are type tuples, where 
you can put a sequence of all your types, and you can iterate on 
them statically with a foreach, to instantiate your templates. So 
your C++ code probably becomes nicer in D.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list