On Thursday, 12 July 2012 at 22:36:19 UTC, Andrei Alexandrescu
wrote:
On 7/12/12 4:49 PM, David Piepgrass wrote:
Yeah, I've been planning to try and get this into D one day.
Probably
something like:
(a ?: b) -> (auto __tmp = a, __tmp ? __tmp : b)
gcc used to have that extension and they dropped it...
But GCC can't control the C++ language spec. Naturally there
is a
reluctance to add nonstandard features. It's a successful
feature in C#,
however, and a lot of people (including me) have also been
pestering the
C# crew for "null dot" (for safely calling methods on object
references
that might be null.)
I don't see why you would use ?: instead of ??, though.
I think we can add coalesce() with any number of lazy arguments
that returns the leftmost argument that is nonzero. It's a
useful function but not frequent enough to warrant an operator.
I Agree. Looking at the Groovy link from Christophe I noticed
their Safe Navigation Operator ?.
Basicly it returns the final value in a dereference chain or null
if any objects in the chain are null:
// a is null if user or address or street is null. No exception
thrown.
auto a = user?.address?.street;
This is a very nice operator that would be tricky to implement as
a function or template.
/Jonas