Templated delegate

Simen kjaeraas simen.kjaras at gmail.com
Mon Jan 10 06:37:00 PST 2011


Mitja <odtihmal at gmail.com> wrote:

> I would like to have a template which returns
> appropriate delegate, something like this:

So like this?

module mod1;

import std.algorithm;
import std.functional;
import std.stdio;

void main( ) {
   auto haystack = ["a","b","c"];
   auto needle = "b";
   auto flt = (string s){return s == needle;};
   auto dg = toDelegate( flt );
   auto result = filter!dg(haystack);
   writeln(result);
}

I would have to argue that the delegate is hardly templated, though. Not
sure what that means.

> What would be the correct way for templated delegate?

Depending on what you mean by 'templated delegate', I would say
std.functional's toDelegate, as used above.

Perhaps if you explained what you mean by 'templated delegate', I could
give a better answer.

-- 
Simen


More information about the Digitalmars-d-learn mailing list