Template return values?

Dmitry Olshansky dmitry.olsh at gmail.com
Tue Dec 4 11:28:25 PST 2012


12/4/2012 10:40 PM, Jonathan M Davis пишет:
> On Tuesday, December 04, 2012 21:43:09 Dmitry Olshansky wrote:
>> Well TDPL claims multiple alias this is allowed so in some distant
>> future it maybe possible for Varaint to alias this to all built-in types.
>
> That would be pretty hideous IMHO. There's a reason that D eschews implicit
> conversions in general. And in this case, you'd very quickly end up with
> accidental conversions which resulted in exceptions being thrown by Variant.

Examples?

> I think that it's _much_ better to require explicit conversions from Variant.

Nope. The point of Variant is to feel natural.
Keep in mind that alias this is highly customizable. I'd expect it to do 
safe narrowing conversions and being only r-value so it will work just fine.

auto x = someVaraint; //NP: x is Varaint
ushort a = x; // implicit conversion that throws on narrowing
x = 32; //is fine x is int
ubyte b = x; //ok, narrowed
x = -1;
b = x; //ConvException

As for exceptions VS compile-time errors - well, there got to be a 
reason to use Varaint, namely having dynamic script-like typing. And 
once there the only way to signal problem is to throw an error, so it is 
a typical situation in dynamic typing world.

-- 
Dmitry Olshansky


More information about the Digitalmars-d-learn mailing list