Adding the ?. operator to D

Paul Backus snarwin at
Thu Sep 17 00:09:43 UTC 2020

On Wednesday, 16 September 2020 at 19:01:28 UTC, Jacob Carlborg 
> I would like that. It should work for an Optional/Nullable type 
> as well. 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`.

Last time this was discussed, someone posted the following 
library version:

T orElse(T)(T value, lazy T alternative)
     return value ? value : alternative;

auto a = A.orElse(B);

More information about the Digitalmars-d mailing list