Template return values?

Era Scarecrow rtcvb32 at yahoo.com
Tue Dec 4 04:59:04 PST 2012


On Tuesday, 4 December 2012 at 12:48:57 UTC, bearophile wrote:
> Era Scarecrow:
>
>> So then in theory
>>
>> Variant v;
>> int i = v.getValue; //calls getValue!int()

  Meant it to be long i, but the idea is the same.

>
> I think this is not possible in D.
>
> This seems possible:
> auto i = v.getValue!int;

  Indeed... it was just a thought, with that you could remove 
certain requirements for overriding opCast, and might handle 
implicit casting... actually that makes sense, allowing for a 
limited number of types you want it to automatically change to 
rather than using 'alias this' to subtype it.

  It also doesn't seem like it would be difficult to add, only 
'auto' would cause any real errors (as it's not a known type it 
can return).


More information about the Digitalmars-d-learn mailing list