C++ Logo


Advanced search

[std-proposals] The null-aware arrow operator: ?->

From: Stéphane Duguay <s_at_[hidden]>
Date: Wed, 19 Oct 2022 23:07:16 -0400
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!


Received on 2022-10-20 03:07:28