std.algorithm issue
Brian Myers
bmyers at harryanddavid.com
Wed May 21 16:13:11 PDT 2008
Hi,
I send Andrei a suggestion a while back for improving the map! template in
std.algorithm. The change was, when map! is supplied a function alias, its
return type should be a range of the return type of the function. This is much
like Python's map statement and lets you do things like this:
string[] string_list = //integer strings from somewhere
auto intrange = map!(atoi)(split(string_list, ","));
That has worked out well. This time I have a question about both the reduce!
and map! templates. I would like to do something like this:
reduce!(Merge)(/*string[] list of files*/);
but where Merge is a member function of a class. When I try this I get:
c:\dmd\bin\..\src\phobos\std\algorithm.d(185): Error: need 'this' to access
member Merge
When I try
reduce!(this.Merge)(/*same string[]*/);
I get:
d_dedup.d(153): template std.algorithm.reduce(F...) cannot deduce template
function from argument types !(this.Merge)(i
variant(char)[],invariant(char)[][])
Is it possible to map! or reduce! a member function or delegate against a
range? If so how would I do that?
Thanx,
Brian
More information about the Digitalmars-d
mailing list