Function names and lambdas
Yuxuan Shui via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Apr 7 11:19:39 PDT 2017
On Thursday, 6 April 2017 at 18:45:26 UTC, Ali Çehreli wrote:
> On 04/06/2017 11:37 AM, Russel Winder via Digitalmars-d-learn
> wrote:
>>[...]
>
> I think it's just a design choice. C implicitly converts the
> name of the function to a pointer to that function. D requires
> the explicit & operator:
>
> alias Func = int function(int);
>
> int foo(int i) {
> return i;
> }
>
> void main() {
> Func[] funcs = [ &foo ];
> }
>
> Close to what you mentioned, name of the function can be used
> as an alias template parameter:
>
> void bar(alias func)() {
> func(42);
> }
>
> int foo(int i) {
> return i;
> }
>
> void main() {
> bar!foo();
> }
>
> Ali
Main reason is probably UFCS.
More information about the Digitalmars-d-learn
mailing list