Related: https://wg21.link/p2561 error propagation operator

On Thu, 20 Oct 2022 at 08:33, Sebastian Wittmeier via Std-Proposals <std-proposals@lists.isocpp.org> 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?->.

 

Sebastian
 

-----Ursprüngliche Nachricht-----
Von: Stéphane Duguay via Std-Proposals <std-proposals@lists.isocpp.org>
Gesendet: Do 20.10.2022 05:07
Betreff: [std-proposals] The null-aware arrow operator: ?->
An: std-proposals@lists.isocpp.org;
CC: Stéphane Duguay <s@binarez.com>;
The null-aware arrow operator: ?->

Instead of:
   if(ptr)
       ptr->func();
Write:
   ptr?->func();

The very bad:
   if( ptr && ptr->getSub() )
       ptr->getSub()->func();
Becomes:
   ptr?->getSub()?->func();

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!

-------
s|d
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals