syntax idea: simplifed ifs

Dan Dan_member at pathlink.com
Fri Apr 21 02:54:20 PDT 2006


>> a && a.doSomething();
>> or
>> a = a || defaultValue;
>> 
>> It feels so much better than:
>> 
>> if(a) a.doSomething();
>> if(!a) a = defaultValue;
>
>	b |= a;
>	writefln(b);
>	a |= b;
>	writefln(a);
>Works quite fine for me.

Dear Alexander,  I'm not sure if you've read the manual on what different
operators do exactly.  || is a logical or, that is, it returns one OR the other.
| is a bitwise or, that is, it returns a value in which if a given bit is set in
the value on either side, it will be set in the return value.

|= is a bitwise or, so if you say:

x = 1;
x |= 2; // 3
x = 1 || 2; // 1
x = 0 || 2; // 2

You with me?





More information about the Digitalmars-d mailing list