opIn_r not detected
Steven Schveighoffer
schveiguy at yahoo.com
Thu Feb 10 05:39:14 PST 2011
On Thu, 10 Feb 2011 07:59:06 -0500, spir <denis.spir at gmail.com> wrote:
> Hello,
>
> Implicite deref of struct pointers on member access works fine for data,
> methods, even special methods with language semantics like opEquals (see
> example below).
> But I cannot have 'in' work with method opIn_r. I get:
> Error: rvalue of in expression must be an associative array, not S*
> What do I have wrong? Or is it a bug: the compiler does not even search
> the struct for opIn_r? But then, why does it do it for opEquals?
>
> Denis
>
> struct S {
> int i;
> void show() { writeln(i); }
> const bool opEquals (ref const(S) s) {
> writeln("==");
> return (i == s.i);
> }
> bool opIn_r (int j) { return (i==j); }
> }
> unittest {
> S* sp = &(S(1));
> writeln(sp.i);
> sp.show();
> S s2 = S(1);
> writeln(sp == s2);
> writeln(1 in sp);
> }
>
There is a bug in the compiler that the message says associative array is
required. There is a bugzilla issue somewhere on that...
But it does look like it should work, I'd file a separate bugzilla on the
opIn_r not working.
-Steve
More information about the Digitalmars-d-learn
mailing list