binary expression...
captain_fid via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat May 21 12:56:00 PDT 2016
On Saturday, 21 May 2016 at 18:33:53 UTC, Anonymouse 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;
>
> bool opEquals(T)(T value) const {
> return value == this.value;
> }
>
> bool opCast(T : bool)() const {
> return this != this.init; // or some such
> }
> }
>
> Not tested, written on my phone so might have missed something.
Perfect.. and your 'phoned-in' coding is impressive.
opCast is the biggest thing I was
missing/forgetting/misunderstanding here.
I Still need to look back at what is happening with vit's
solution.
Sorry again for the bad example to both of you.
More information about the Digitalmars-d-learn
mailing list