Compile-time exceptions

bearophile bearophile at lycos.com
Tue Nov 25 04:28:53 PST 2008


Christopher Wright Wrote:
> I don't know what this is doing. That code fragment won't compile, and 
> it isn't showing usage.

Sorry:

struct _add { T opCall(T.init + T.init)(T x) { return x+x; } }
_add add;

Now you can give it to a function, without the need of specializing it for a type T first (you can't give the pointer to a template). (This may also be faster, because there isn't a delegate to call).
(Haskell is statically typed and allows you do more complex things with a clean enough syntax).


> Virtual templates would allow you to use polymorphism in this case, but 
> that's not going to be considered for quite some time, if at all.

Can you explain?

Bye,
bearophile



More information about the Digitalmars-d mailing list