On Monday, 7 December 2015 at 11:40:45 UTC, Martin6265 wrote:
Hello,
I think nullable condition operator and null coalescending
operator should be a nice new features in D.
https://msdn.microsoft.com/library/dn986595.aspx
https://msdn.microsoft.com/library/ms173224.aspx
Same as operator `as`
https://msdn.microsoft.com/library/cscsdfbt.aspx
Why?
Is better to write
(variable as FooBar)?.callMethod();
than
auto var = cast(FooBar)variable;
if (var !is null)
var.callMethod();
or
auto x = (variable as FooBar)?.getRandomNumber() ?? 42;
As per Rumbu's link, D is powerful enough to implement this in a
library function, and have it optimize down to a set of if-else
statements.