On Saturday, 21 May 2016 at 18:31:46 UTC, vit wrote:
On Saturday, 21 May 2016 at 18:10:55 UTC, captain_fid wrote:
Please forgive if asked before. My google skills seemed to fail me and didn't see any result from search.

My problem is simple (though not my understanding LOL).

struct D {
      int value;
bool opEquals()(bool value) const { return (value == value); }
}

D aD;
if (aD == 1) { // OK
}

if (aD) { // Error: expression aD of type D does not have a boolean value
}

Is there a way to overload for this? What am I missing?

struct D {
        int value;

        alias value this;    ///"implicit cast"
        
        bool opEquals()(bool value) const {
          return (this.value == value);                 ///'this.' is required
        }
}

Thanks both vit and anonymouse. (And I couldn't even provide a good example -- didn't mean to use 'value' for opEquals() arg .... argggggg

Regardless -- vit, your suggestion compiled (and I laughed) but I'm not sure what's getting called. The opEquals() overload doesn't seem to be it. Hard returns of true or false don't seem to impact code. Hmmm.

I'll also check anoymouse's suggestion.

Regardless, thanks for the assistance.

Reply via email to