setIntersection of struct range

Sergey Gromov snake.scaly at gmail.com
Wed Aug 12 15:43:39 PDT 2009


Tue, 11 Aug 2009 19:35:40 -0400, Jesse Phillips wrote:

> 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."

Looks like a compiler bug/feature to me.  The following is a reduced
test case:

import std.functional;

struct S {
    string label;
}

void main() {
    auto f1 = &binaryFunImpl!("a < b", "a", "b").result!(int, int);
    auto f2 = &binaryFunImpl!("a.label < b.label", "a", "b").result!(S, S);
}

Compiled with dmd2 test.d:

C:\opt\dmd.2.031\windows\bin\..\..\src\phobos\std\functional.d(191):
Error: static assert  "Bad binary function q{a.label < b.label}. You
need to use a valid D expression using symbols a of ty
pe S and b of type S."

Note that int,int passes while S,S fails.


More information about the Digitalmars-d-learn mailing list