Remus

Namespace rswhite4 at googlemail.com
Thu Dec 6 06:32:41 PST 2012


> But take care of this. If you write int[] arr = 
> other_arr.length ?: [1, 2, 3]; You don't get only 'other_arr', 
> but 'other_arr.length'. This is because of using member 
> functions/propoerties with elvis operators.

Improved.
Examples:

// declaration of vars...
int[] values = vars[].length == 0 ?: [1, 2, 3];
or
int[] values = vars[].length != 0 ?: [1, 2, 3];
or
int[] values = vars[].length > 0 ?: [1, 2, 3];

will be converted to:
int[] values = vars[].length == 0 ? vars[] : [1, 2, 3];

But if you write:
int[] values = vars[].length ?: [1, 2, 3];

you get:
int[] values = vars[].length == 0 ? vars.length : [1, 2, 3];

So if you have a compare operator after the last .property, only 
the identifiers before that will be taken.


More information about the Digitalmars-d-announce mailing list