Unexpectedly nice case of auto return type

Basile B. b2.temp at gmx.com
Wed Dec 4 09:03:09 UTC 2019


On Tuesday, 3 December 2019 at 23:44:59 UTC, mipri wrote:
> On Tuesday, 3 December 2019 at 10:13:30 UTC, mipri wrote:
>> Speaking of nice stuff and aliases, suppose you want to
>> return a nice tuple with named elements?
>>
>> Option 1: auto
>>
>>   auto option1() {
>>       return tuple!(int, "apples", int, "oranges")(1, 2);
>>   }
>>
>> Option 2: redundancy
>>
>>   Tuple!(int, "apples", int, "oranges") option2() {
>>       return tuple!(int, "apples", int, "oranges")(1, 2);
>>   }
>>
>> Option 3: an alias
>>
>>   alias BadMath = Tuple!(int, "apples", int, "oranges");
>>
>>   BadMath option3() {
>>       return BadMath(1, 2);
>>   }
>
> Option 4: typeof(return)
>
>   Tuple!(int, "apples", int, "oranges") option4() {
>       return typeof(return)(1, 2);
>   }

aha nice


More information about the Digitalmars-d-learn mailing list