The in operator (along with other things) is designed poorly.

Ruby The Roobster michaeleverestc79 at gmail.com
Tue May 31 00:48:57 UTC 2022


On Tuesday, 31 May 2022 at 00:16:46 UTC, Ruby The Roobster wrote:
> ...

To add to my previous post, I present this:

```d

struct A
{
     this(int a)
     {
         this.a = a;
     }
     int a;
     A opBinary(string op)(A rhs)
     {
         mixin("return A(a " ~ op ~ "rhs.a);");
     }
     A opBinaryRight(string op)(A lhs)
     {
         mixin("return A(lhs.a " ~ op ~ "rhs.a);");
     }
}
void main(){
     import std;
     auto c = A(1) + A(2);
}
```

This doesn't compile because the argument lists for, to quote the 
compiler:

Error: overloads `@system A(A rhs)` and `(A lhs)` both match 
argument list for `opBinary`

This is stupid, because in the example from the spec, the 
argument lists were the same, and it still compiled.  This seems 
to be a bug.


More information about the Digitalmars-d mailing list