setIntersection of struct range
Jesse Phillips
jessekphillips+d at gmail.com
Tue Aug 11 16:35:40 PDT 2009
I am trying to obtain a rang that is the intersection of two other ranges. To do this I am using the _setIntersection()_ function.
import std.algorithm;
import std.stdio;
struct S {
string label;
}
void main() {
auto s1 = new S[2];
auto s2 = new S[2];
s1[0].label = "fish";
s1[1].label = "bar";
s2[0].label = "foo";
s2[1].label = "fish";
foreach(str; setIntersection(s1,s2))
writeln(str);
}
The code above generates this error:
C:\opt\dmd\windows\bin\..\..\src\phobos\std\functional.d(191):
Error: static assert "Bad binary function q{a < b}.
You need to use a valid D expression using symbols a of type S and b of type S."
So I attempted an intersection of string arrays, and received a different error. I'm not sure if I am at fault or the compiler. Shouldn't these work?
import std.algorithm;
import std.stdio;
import std.array;
struct S {
string label;
}
void main() {
auto s1 = ["fish", "bar"];
auto s2 = ["foo", "fish"];
foreach(str; setIntersection(s1,s2))
writeln(str);
}
Which ended up with:
test.d(13): Error: template std.algorithm.setIntersection(alias less = "a < b",Rs...)
if (allSatisfy!(isInputRange,Rs)) does not match any function template declaration
test.d(13): Error: template std.algorithm.setIntersection(alias less = "a < b",Rs...)
if (allSatisfy!(isInputRange,Rs)) cannot deduce template function from
argument types !()(immutable(char)[][2u],immutable(char)[][2u])
test.d(13): Error: foreach: int is not an aggregate type
More information about the Digitalmars-d-learn
mailing list