Function names and lambdas

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Apr 7 14:05:13 PDT 2017


On 04/07/2017 11:19 AM, Yuxuan Shui wrote:
 > 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.

Main reason for D not supporting the name-to-pointer mapping? I don't 
think so because as far as I know this has been the case since very 
early on but UFCS came very much later.

Ali



More information about the Digitalmars-d-learn mailing list