opEquals() non-standard return type

Ali Çehreli acehreli at yahoo.com
Thu Jan 24 00:47:37 UTC 2019


On 01/23/2019 07:19 AM, Jacob Shtokolov wrote:

 > Expressions like `User.id == 10`, `User.age > 18`, etc. should return a
 > struct instead of a bool (let's call it `struct BinaryExpression`).

Have you considered 'alias this'?

struct BinaryExpr(T)
{
   T left;
   T right;
   Op op;

   bool value() const {
     final switch (op) with (Op) {
       case Equals:
         return left == right;
       case NotEquals:
         return left != right;
     }
   }

   alias value this;
}

 > So I'm making the two versions of opEquals: one returns a
 > BinaryExpression, and the second - a boolean value.

Yeah, that can't work. Remove the bool-returning one and your code works 
with the 'alias this' above.

Ali



More information about the Digitalmars-d-learn mailing list