Re: Is it possible to override the behavior of a type when used in a conditional expression?

2016-09-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/10/16 6:47 PM, Jonathan M Davis via Digitalmars-d-learn wrote: No. That's how it's been for years now - certainly well before TDPL was released - and I suspect that it was that way in D1 (though I've never really used D1, so I'm not sure). It's not that way in D1. I think it was added

Re: Is it possible to override the behavior of a type when used in a conditional expression?

2016-09-10 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, September 10, 2016 14:29:33 pineapple via Digitalmars-d-learn wrote: > On Saturday, 10 September 2016 at 14:24:23 UTC, ag0aep6g wrote: > > On 09/10/2016 04:10 PM, pineapple wrote: > >> I've got a struct and it would be very convenient if I could > >> specify > >> what happens when I

Re: Is it possible to override the behavior of a type when used in a conditional expression?

2016-09-10 Thread ag0aep6g via Digitalmars-d-learn
On 09/10/2016 04:29 PM, pineapple wrote: Was this a recent addition to the language? I don't think so.

Re: Is it possible to override the behavior of a type when used in a conditional expression?

2016-09-10 Thread pineapple via Digitalmars-d-learn
On Saturday, 10 September 2016 at 14:24:23 UTC, ag0aep6g wrote: On 09/10/2016 04:10 PM, pineapple wrote: I've got a struct and it would be very convenient if I could specify what happens when I write `if(value)` - is this possible? `if (value)` implies a cast to bool. Define opCast!bool and

Re: Is it possible to override the behavior of a type when used in a conditional expression?

2016-09-10 Thread ag0aep6g via Digitalmars-d-learn
On 09/10/2016 04:10 PM, pineapple wrote: I've got a struct and it would be very convenient if I could specify what happens when I write `if(value)` - is this possible? `if (value)` implies a cast to bool. Define opCast!bool and it gets called: struct S { bool opCast(T : bool)() {

Is it possible to override the behavior of a type when used in a conditional expression?

2016-09-10 Thread pineapple via Digitalmars-d-learn
I've got a struct and it would be very convenient if I could specify what happens when I write `if(value)` - is this possible?