C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Use optional<T> as though it were T

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Tue, 4 Jul 2023 15:44:01 +0100
On Tue, Jul 4, 2023 at 8:10 AM Harald Achitz via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> Wouldn't it make more sense to have a (new) optional with a different operator dot behavior?
>
> n4477.pdf (open-std.org)
>
> p0252r2.pdf (open-std.org)
>
> This is just an other use-case why it's sad that this topic does not get the attention it deserves.



This may sound like an over-simplification, but what if the 'dot'
operator and the 'arrow' operator were swapped for a new type
"std::optional_direct".

So you would do emplace as follows:

    obj->emplace(.......):

And you would call member functions as follows:

    obj.SomeMethod(...........):

I suppose then we just have to discuss what happens when "operator->"
is overloaded..

Received on 2023-07-04 14:44:15