Some problems with operator overloading

Steven Schveighoffer schveiguy at yahoo.com
Tue Mar 16 06:08:16 PDT 2010


On Mon, 15 Mar 2010 16:59:53 -0400, Trass3r <un at known.com> wrote:

>> I can see one potential reason to use opBinary("==") and that is to  
>> collect binary operator code in one place.
>
> Currently dmd checks that and turns == into opEquals, should never  
> become opBinary!("==")

What I meant was, opEquals could forward to opBinary, but if it's  
disallowed by the compiler, then that's not possible.  Also, if you  
defined opBinary like this:

auto opBinary(string op)(const ref T rhs)
{
...
}

Then should the compiler disallow this?  opBinary!("==") will compile.  I  
just think it's overkill to restrict what functions are valid arbitrarily.

-Steve



More information about the Digitalmars-d mailing list