Null-Coalescing Operator and Extensions
Basile B.
b2.temp at gmx.com
Mon Aug 27 08:16:24 UTC 2018
On Saturday, 25 August 2018 at 19:16:26 UTC, Jacob Carlborg wrote:
> On 2018-08-25 15:33, SG wrote:
>> Hi,
>>
>> 1) I program in C# and I'm wondering if there is something
>> like ?? (Null-Coalescing Operator) in D? (I remember some
>> proposals in the past).
>
> Not in the language but it can be implemented as a library
> function by overloading "opDispatch". See [1] for an example.
>
> [1]
> https://github.com/jacob-carlborg/dlp/blob/9d524e282803070022848c01cf6cd25a61025004/source/dlp/core/optional.d#L228-L238
In the same vain there's "safeAccess" in my user library, see
https://github.com/BBasile/iz/blob/master/import/iz/sugar.d#L1658. It's more or less the same specific D pattern (opDispatch), although the OP asked for "??" and not for "?.", which is strange. I find that the later misses more as a builtin operator.
More information about the Digitalmars-d-learn
mailing list