Suggestion: "new delegate" - delegates useable outside of the nesting function scope

Tom S h3r3tic at remove.mat.uni.torun.pl
Wed Jun 14 13:43:45 PDT 2006


Markus Dangl wrote:
> You might find my "AdvancedDelegate" library useful, i recently posted 
> it to the announce newsgroup. Using its templates for partial 
> application of functions and delegates, you can do something very 
> similiar to the code above:
> 
> AdvancedDelegate0!(char) createFileReader(char[] fileName)
> {
>     auto File f = new File(fileName, FileMode.In);
> 
>     auto readerFunc = AdvancedDelegate(
>         function char(File f)
>         {
>             return f.getc();
>         }
>     );
>     return readerFunc(f);
> }

Hmm.. what's stopping you from returning a 'normal' delegate, thru 
return &readerFunc(f).Eval or &readerFunc(f).opCall ? it would make more 
sense to functions which accept char delegate() and have no idea what 
AdvancedDelegate0!(char) is :)



-- 
Tomasz Stachowiak  /+ a.k.a. h3r3tic +/



More information about the Digitalmars-d mailing list