Instantiating templates where type is known only at run time

Craig Dillabaugh cdillaba at cg.scs.carleton.ca
Tue Nov 19 16:41:36 PST 2013


On Tuesday, 19 November 2013 at 12:53:50 UTC, bearophile wrote:
> 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

Thanks very much.
Craig


More information about the Digitalmars-d-learn mailing list