Compile-time exceptions
Denis Koroskin
2korden at gmail.com
Tue Nov 25 04:34:14 PST 2008
On Tue, 25 Nov 2008 15:28:53 +0300, bearophile <bearophile at lycos.com>
wrote:
> 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;
>
Did you mean:
struct _add { typeof(A.init+B.init) opCall(A, B)(A a, B b) { return a + b;
} }
_add add;
auto x = add(3, 0.1415926); ?
> 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).
>
Yes, it is a nice trick.
More information about the Digitalmars-d
mailing list