Return type deduction

Andrea Fontana via Digitalmars-d digitalmars-d at puremagic.com
Wed Sep 7 00:19:15 PDT 2016


On Tuesday, 6 September 2016 at 14:21:26 UTC, Steven 
Schveighoffer wrote:
> On 9/5/16 5:59 AM, Andrea Fontana wrote:
>> I asked this some time (years?) ago. Time for a second try :)
>>
>> Consider this:
>>
>> ---
>>
>> T simple(T)() { return T.init; }
>>
>>
>> void main()
>> {
>>     int test = simple!int(); // it compiles
>>     int test2 = simple();    // it doesn't
>
>       auto test3 = simple!int();
>
> Granted, you are still typing "auto", but only specify the type 
> once.
>
> -Steve

Only for the simple case.

It would interesting if it would work for:

struct Blah
{
    string name;
}

Blah b;
b.name = simple();


or:

void myFunc(string s) { ... }
myFunc(simple());

Andrea






More information about the Digitalmars-d mailing list