The new ?? and ??? operators

Arlen Albert Keshabyan arlen.albert at gmail.com
Sun Sep 23 10:30:29 PDT 2007


Vladimir Panteleev Wrote:

> On Sun, 23 Sep 2007 18:34:09 +0300, Arlen Albert Keshabyan <arlen.albert at gmail.com> wrote:
> 
> [regarding ???]
> > The lvalue gets the first rvalue that evaluates to true (evaluation goes from left to right). 
> 
> So the result can only be boolean?
> In this case, I don't understand how
>   a = b ??? c ??? d;
> is different from
>   a |= b || c || d;
> 
> If b, c and d are false then a is unchanged.
> 
> -- 
> Best regards,
>  Vladimir                          mailto:thecybershadow at gmail.com


Consider this:

int v = 15;
int v2 = 30;

int a = v > 20 ??? v = 17 ??? v2 < 25 ??? 5;

in this case 'a' evaluates to 5 because none of the conditions evaluate to true except the last one. if you remove the last condition (??? 5) then 'a' stays 0 in this case.

If v2 = 23 then 'a' evaluates to 23;
If v = 27 then 'a' evaluates to 27;

etc.

It means that it takes a sequential rvalue, tests it against a condition and if the condition evaluates to true then it assigns that rvalue to lvalue. It does not mean you are restricted to boolean values only.



More information about the Digitalmars-d mailing list