C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Calling methods on a nullptr

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Thu, 31 Oct 2024 13:06:09 +0000
On Thu, 31 Oct 2024 at 12:06, Sebastian Wittmeier via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> There are all kind of monadic expressions for testing for a value or error:
>
>
>
> https://en.cppreference.com/w/cpp/utility/optional/value_or
>
> https://en.cppreference.com/w/cpp/utility/optional/or_else
>
> https://en.cppreference.com/w/cpp/utility/optional/and_then
>
> https://en.cppreference.com/w/cpp/utility/optional/transform
>
>
>
> https://en.cppreference.com/w/cpp/utility/expected/value_or
>
> https://en.cppreference.com/w/cpp/utility/expected/or_else
>
> https://en.cppreference.com/w/cpp/utility/expected/and_then
>
> https://en.cppreference.com/w/cpp/utility/expected/transform
>
> https://en.cppreference.com/w/cpp/utility/expected/transform_error
>
>
>
> Also there is a proposal for operator?? renamed try?
>
> https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2561r2.html
>

Because baking that behaviour into the class so that the null check happens
*after* dereferencing the pointer is the wrong place to do it, and is less
flexible.

Received on 2024-10-31 13:07:30