What are the differences between these forms of function-like declarations ?

Ali Çehreli acehreli at yahoo.com
Wed Sep 5 23:42:06 PDT 2012


On 09/05/2012 11:31 PM, Anderel Cerol wrote:
 > On Thursday, 6 September 2012 at 05:18:24 UTC, Anderel Cerol wrote:
 >>
 >>>
 >>> a real example is :
 >>> ....
 >>> import std.net.curl;
 >>> auto http=HTTP();
 >>> ...
 >>> http.onReceiveStatusLine(...);
 >>> ...
 >>>
 >>> the function http.onReceiveStatusLine(...) is exactly what the
 >>> function on(...) is above.
 >>> The environment is dmd 2.060 Windows.
 >> plus, what passes to the http.onReceiveStatusLine is just
 >> (a){a.writeln();} with different forms above.
 >
 > by the way ,std.functional.toDelegate doesn't work as UFCS style,why ?

Can you be more specific please: What "doesn't work"? The following code 
is slightly modified from toDelegate's documentation, demonstrating that 
it indeed does work with UFCS:

import std.stdio;
import std.functional;

void doStuff() {
     writeln("Hello, world.");
}

void runDelegate(void delegate() myDelegate) {
     myDelegate();
}

void main()
{
     // auto delegateToPass = toDelegate(&doStuff);
     auto delegateToPass = (&doStuff).toDelegate();
     runDelegate(delegateToPass);  // Calls doStuff, prints "Hello, world."
}

Ali



More information about the Digitalmars-d mailing list