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

Anderel Cerol w_sholmes at hotmail.com
Thu Sep 6 22:56:39 PDT 2012


On Thursday, 6 September 2012 at 06:41:37 UTC, Ali Çehreli wrote:
> 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

I coded like this :
auto func ={
......
};
import std.functional;
func.toDelegate(); //doesn't work ,shows "undefined identifier 
toDelegate "
toDelegate(func); //works.


More information about the Digitalmars-d mailing list