Thread overview | ||||||
---|---|---|---|---|---|---|
|
March 09, 2010 [phobos] Fw: cast(bool) vs. opUnary!"!" | ||||
---|---|---|---|---|
| ||||
D'oh!
Sorry, this went to the old list.
-Steve
----- Forwarded Message ----
> From: Steve Schveighoffer <schveiguy at yahoo.com>
> To: Phobos <phobos at erdani.com>
> Sent: Tue, March 9, 2010 9:30:16 AM
> Subject: cast(bool) vs. opUnary!"!"
>
> In the latest dmd 2.041, cast!T was added, and if statements were changed to do:
>
> if(s) => if(cast!bool(s))
>
> What happened to if translating to:
>
> if(!!s)
>
> which translates to ! opUnary!("!). Hm... that's a lot of !'s :)
>
> I thought that was the plan, at least it was in the book. Is that going away?
>
> It does make more sense to use cast(bool) because opUnary!"!" could potentially return a non-bool value.
>
> -Steve
|
March 09, 2010 [phobos] Fw: cast(bool) vs. opUnary!"!" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steve Schveighoffer | Walter and I agreed that cast to bool is as good as opUnary. Overloading unary "!" is now not possible.
Andrei
Steve Schveighoffer wrote:
> D'oh!
>
> Sorry, this went to the old list.
>
> -Steve
>
>
>
> ----- Forwarded Message ----
>> From: Steve Schveighoffer <schveiguy at yahoo.com>
>> To: Phobos <phobos at erdani.com>
>> Sent: Tue, March 9, 2010 9:30:16 AM
>> Subject: cast(bool) vs. opUnary!"!"
>>
>> In the latest dmd 2.041, cast!T was added, and if statements were changed to do:
>>
>> if(s) => if(cast!bool(s))
>>
>> What happened to if translating to:
>>
>> if(!!s)
>>
>> which translates to ! opUnary!("!). Hm... that's a lot of !'s :)
>>
>> I thought that was the plan, at least it was in the book. Is that going away?
>>
>> It does make more sense to use cast(bool) because opUnary!"!" could potentially return a non-bool value.
>>
>> -Steve
>
>
>
>
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
|
March 09, 2010 [phobos] Fw: cast(bool) vs. opUnary!"!" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | The only thing it disallows is making !x return something other than a bool. The only place I can think of that would be useful is some sort of logic type that has more than 2 states, but that's a stretch.
The current implementation looks good to me, I was just curious about it.
-Steve
----- Original Message ----
> From: Andrei Alexandrescu <andrei at erdani.com>
>
> Walter and I agreed that cast to bool is as good as opUnary. Overloading unary "!" is now not possible.
>
> Andrei
|
March 09, 2010 [phobos] Fw: cast(bool) vs. opUnary!"!" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steve Schveighoffer | Steve Schveighoffer wrote:
> The only thing it disallows is making !x return something other than a bool.
That's a bug. We must NOT have several redundant and potentially contradictory ways of defining interlinked features. The "!" operator is NOT overloadable, and !x must be rewritten to !x.opCast!bool().
Andrei
|
Copyright © 1999-2021 by the D Language Foundation