Adding the ?. operator to D

Per Nordlöw per.nordlow at gmail.com
Sat Sep 12 16:51:20 UTC 2020


Has there been any discussions on adding the ?. operator to 
simplify structure matching on class trees typically found in 
compilers such as dmd.

Basically, implemented via lowering of

     C ?. EXPR

to

     C ? C.EXPR : EXPR.init

when EXPR has type class or pointer and for the other cases either

     C ? C.EXPR : EXPR.init

or perhaps even

     C ? C.EXPR : nullable(EXPR).init

if nullable is made part of the runtime or even builtin.

Given that `C` is a class or pointer to an aggregate.

C# supports has this [1].

[1] 
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/member-access-operators#null-conditional-operators--and-


More information about the Digitalmars-d mailing list