Adding the ?. operator to D
Russel Winder
russel at winder.org.uk
Thu Sep 17 03:50:23 UTC 2020
On Wed, 2020-09-16 at 21:01 +0200, Jacob Carlborg via Digitalmars-d wrote:
> It's a good idea to add an `??` operator at the same time as well:
>
> auto a = A ?? B;
>
> if `A` is not null, assign `A` to `a`. Otherwise assign `B` to `a`.
Groovy 1.5 introduced the Elvis Operator, ?:, for this, and most other JVM
languages have since followed suit. It seems though GNU C and C++ got there
first: https://en.wikipedia.org/wiki/Elvis_operator
a = x ?: y
is
a = x ? x : y
with the semantics "if x does not have Boolean evaluation false then x else
y".
--
Russel.
===========================================
Dr Russel Winder t: +44 20 7585 2200
41 Buckmaster Road m: +44 7770 465 077
London SW11 1EN, UK w: www.russel.org.uk
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20200917/f8ee9fec/attachment.sig>
More information about the Digitalmars-d
mailing list