Proposal : allocations made easier with non nullable types.
Daniel Keep
daniel.keep.lists at gmail.com
Mon Feb 9 05:49:26 PST 2009
Ary Borenszweig wrote:
> How would you do this?
>
> X x;
>
> if(someCondition) {
> x = new SomeX();
> } else {
> x = new SomeOtherX();
> }
One option is the "turn everything into an expression" route. This is
what Nemerle (think a functional superset of C#) did, and it's just
BEAUTIFULLY expressive.
> X x = if( someCondition ) new SomeX(); else new SomeOtherX();
Failing that, there's always this (note: didn't do a syntax check on
this :P):
> X x = ({if(someCondition)
> return new SomeX();
> else return new SomeOtherX();})();
Or something to that effect.
-- Daniel
More information about the Digitalmars-d
mailing list