Ranges tutorial

Willy Martinez wmartinez at thisisnotmyrealemail.com
Sat Jul 16 13:13:34 PDT 2011


== Quote from Johann MacDonagh (johann.macdonagh.no at spam.gmail.com)'s article
> However, for what you want, you can use std.algorithm.filter

OK. Followed your advice and this is what I've got so far:

import std.algorithm;
import std.file;
import std.stdio;

void main(string[] args) {
	auto needle = boyerMooreFinder(args[1]);
	foreach (string name; dirEntries(".", SpanMode.shallow)) {
		if (name[$-3 .. $] == "txt") {
			writeln(name);
			string text = readText(name);
			auto haystack = filter!("a >= '0' && a <= '9'")(text);
			auto result = find(haystack, needle);
			writeln(result);
		}
	}
}

Passing the haystack filter to find() produces the following error:

..\..\src\phobos\std\algorithm.d(2912): Error: function std.
algorithm.BoyerMooreFinder!(result,string).BoyerMooreFinder.beFound (string
haystack) is not callable using argument types (Filter!(result,string))
..\..\src\phobos\std\algorithm.d(2912): Error: cannot implicitly convert
expression (haystack) of type Filter!(result,string) to string
..\..\src\phobos\std\algorithm.d(2912): Error: cannot implicitly convert
expression (needle.beFound((__error))) of type string to Filter!(result,string)
search_seq.d(12): Error: template instance
std.algorithm.find!(Filter!(result,string),result,string) error instantiating

What could be the problem?

Thanks


More information about the Digitalmars-d-learn mailing list