Related: error propagation operator

On Thu, 20 Oct 2022 at 08:33, Sebastian Wittmeier via Std-Proposals <> wrote:

Hi Stephane,


the ternary operator ? has the current disadvantage that it cannot be customized.

Customization of ?-> could be useful for smart pointers and iterators, when the test should do more than test for false the pointer converted into bool.


Even if a 3-argument operator? or operator?-> would be introduced, with current function call semantics, all parameters are evaluated before the function call, which would nullify the check for nullptr.


Similarly && and || cannot be customized fully.


Perhaps there are ideas for partial evaluations of function parameters in general (e.g. "lambda parameters", which can be evaluated in a delayed manner by the called function (internally implementable as callback) or some fixed ways for certain operators like operator?, operator??, operator||, operator?->.



-----Ursprüngliche Nachricht-----
Von: Stéphane Duguay via Std-Proposals <>
Gesendet: Do 20.10.2022 05:07
Betreff: [std-proposals] The null-aware arrow operator: ?->
CC: Stéphane Duguay <>;
The null-aware arrow operator: ?->

Instead of:

The very bad:
   if( ptr && ptr->getSub() )

Support for the "default value if ptr is null" use case:
   n = ptr?->get_value() : 42;
Instead of:
   n = ptr ? ptr->get_value() : 42;

The  three-way comparison operator <=> is 3 chars long; ?-> now seems
reasonable IMHO.

I'm unsure of all the possibilities for null-aware operators in C++,
but there's probably more to explore. I couldn't find anything in
relation to "null-aware" on the mailing list archive. "Null safety"
itself is a wider concept than null-awareness. If this was already
posted, sorry!

Std-Proposals mailing list

Std-Proposals mailing list