On Mon, 20 Feb 2012 21:08:07 -0600, H. S. Teoh <[email protected]> wrote:

On Mon, Feb 20, 2012 at 08:41:47PM -0600, Andrei Alexandrescu wrote:
On 2/20/12 8:33 PM, Robert Jacques wrote:
>Variant e = new MyException();
>writeln( e.filename, e.line, e.column);
>
>Aren't __traits and opDispatch fun?

I thought the same, but was afraid to bring the nuclear bomb out :o).
[...]

Mmm... but *this* nuclear bomb, I like. :-)


T

It gets better, you can also create prototype objects:

    Variant p1 = Tuple!(real,"x",real,"y")(1,2);

    Variant p2;                        // An unitialized Variants attemps to 
convert
    p2.x = 1;                          // itself to Variant[string] on 
assignment
    p2.__reflect("y",Variant(2) );
    p2["opBinary!+"]  = (Variant a, real b   ){return b;  }; // Create an 
'operator'
    p2["opBinary!+"] ~= (Variant a, Variant b){return a.x;}; // overload set

    assert( (p2 + 4) == 4 && (p2 + p1) == 1);

Reply via email to