The new ?? and ??? operators

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


Janice Caron Wrote:

> On 9/23/07, Arlen Albert Keshabyan <arlen.albert at gmail.com> wrote:
> > 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.
> 
> I assume you meant v == 17, not v = 17 there, since v = 17 would be an
> assignment. In any case
> 
> int a = v > 20 ??? v == 17 ??? v2 < 25 ??? 5;
> 
> Looks to me the same as
> 
> int a = v > 20 ? v : (v == 17 ? v : (v2 < 25 ? v2 : 5));
> 
> Could be just me, but the latter seems readable and more expressive.

Well, maybe you're right.



More information about the Digitalmars-d mailing list