The Right Approach to Exceptions
Robert Jacques
sandford at jhu.edu
Tue Feb 21 06:01:46 PST 2012
On Mon, 20 Feb 2012 21:08:07 -0600, H. S. Teoh <hsteoh at quickfur.ath.cx> 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);
More information about the Digitalmars-d
mailing list