www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How do I get an array from filter's result?

reply "Nick Sabalausky" <a a.a> writes:
On 2.047, this:

import std.algorithm;
import std.array;
void main()
{
    string[] result =
        array(
            filter!( (string a) { return a != "b"; } )
            (["a", "b", "c"])
        );
}

Gives me this:

testfilter.d(6): Error: template std.array.array(Range) if 
(isForwardRange!(Range)) does not match any function template declaration
testfilter.d(6): Error: template std.array.array(Range) if 
(isForwardRange!(Range)) cannot deduce template function from argument types 
!()(Filter!(__dgliteral1,string[])) 
Jul 27 2010
parent Jonathan M Davis <jmdavisprog gmail.com> writes:
On Tuesday, July 27, 2010 17:24:27 Nick Sabalausky wrote:
 On 2.047, this:
 
 import std.algorithm;
 import std.array;
 void main()
 {
     string[] result =
         array(
             filter!( (string a) { return a != "b"; } )
             (["a", "b", "c"])
         );
 }
 
 Gives me this:
 
 testfilter.d(6): Error: template std.array.array(Range) if
 (isForwardRange!(Range)) does not match any function template declaration
 testfilter.d(6): Error: template std.array.array(Range) if
 (isForwardRange!(Range)) cannot deduce template function from argument
 types !()(Filter!(__dgliteral1,string[]))

The forward range stuff is broken in 2.047. save() was added to the definition for isForwardRange(), but a bunch of forward ranges didn't get it added. It's been fixed in svn. - Jonathan M Davis
Jul 27 2010