Introducing Nullable Reference Types in C#. Is there hope for D, too?
RomanZ
zrrole at ya.ru
Sun Nov 19 03:06:51 UTC 2017
Is it possible to somehow change the concept of uninitialized
values to something like 'zeroOrOne' instead of 'null'?
Instrument instrument1 = new Instrument();
Instrument instrument2 = new Instrument();
zeroOrOne!Instrument getInstrument() {
zeroOrOne!Instrument instrument;
if( instrument1.power > 10 ) instrument = instrument1;
else if( instrument2.power > 5 ) instrument = instrument2;
return instrument;
}
//zeroOrOne!Instrument instead of 'InstrumentOrNull'
auto instrument = getInstrument();
/*1*/ instrument.setPower( 20.4f );
/*2*/ instrument.doit();
/*3*/ instrument1.setPower = 20;
instrument = getInstrument();
/*4*/ instrument.doit();
/*5*/ instrument.setPower( 20.4f );
/*
1: opDispatch: setPower
2: opDispatch: doit
3: Instrument.setPower: 20
4: opDispatch: doit
4: Instrument.doit;
5: opDispatch: setPower
5: Instrument.setPower: 20.4
*/
More information about the Digitalmars-d
mailing list