Should aliasing a lambda expression be allowed?
Meta
jared771 at gmail.com
Thu Nov 16 16:10:50 UTC 2017
On Thursday, 16 November 2017 at 13:05:51 UTC, Petar Kirov
[ZombineDev] wrote:
> On Wednesday, 15 November 2017 at 19:29:29 UTC, Steven
> Schveighoffer wrote:
>> On 11/15/17 11:59 AM, Andrea Fontana wrote:
>>> On Wednesday, 15 November 2017 at 15:25:06 UTC, Steven
>>> Schveighoffer wrote:
>>>> alias foo = lambda1;
>>>> alias foo = lambda2;
>>>
>>> What?
>>
>> Yep. Would never have tried that in a million years before
>> seeing this thread :) But it does work. Tested with dmd
>> 2.076.1 and 2.066. So it's been there a while.
>>
>> -Steve
>
> I guess you guys haven't been keeping up with language changes
> :P
>
> https://dlang.org/changelog/2.070.0.html#alias-funclit
>
> And yes, you can use 'alias' to capture overload sets.
> See also:
>
> https://github.com/dlang/dmd/pull/1660/files
> https://github.com/dlang/dmd/pull/2125/files#diff-51d0a1ca6214e6a916212fcbf93d7e40
> https://github.com/dlang/dmd/pull/2417/files
> https://github.com/dlang/dmd/pull/4826/files
> https://github.com/dlang/dmd/pull/5162/files
> https://github.com/dlang/dmd/pull/5202
>
> https://github.com/dlang/phobos/pull/5818/files
Yes, as far as I understand this is just the normal way that you
add a symbol to an existing overload set, except now it also
interacts with the functionality of using an alias to create a
named function literal. Kind of interesting because I don't think
it was possible to do this before, e.g.:
int function(int) f1 = (int n) => n;
int function(int) f2 = (char c) => c;
Would obviously be rejected by the compiler. However, using the
alias syntax we can create an overload set from function
literals in addition to regular functions.
More information about the Digitalmars-d
mailing list