C++ Logo

std-proposals

Advanced search

Re: std::as

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Tue, 27 Oct 2020 11:42:53 -0400
On Tue, Oct 27, 2020 at 6:16 AM Miguel Ojeda via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> On Mon, Oct 26, 2020 at 8:18 PM Arthur O'Dwyer via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
> >
> > However, I would still !vote against such a proposal, because the fact remains that `*std::get_if<int>(&v)` has the same normative effect, and is shorter to type, and is idiomatic C++17 already. I don't think C++23 needs a new idiom to sit alongside the existing C++17 idiom. In particular, I want to be able to keep using `*std::get_if<int>(&v)` in my C++17 and C++20 codebases and get the optimization, without needing to rewrite any code. If the optimization is available only to C++23 codebases, and if I have to make a `git commit` touching the code before the compiler will deign to optimize it, that's not so useful to me.
>
> Simple and proper APIs that reflect the proper intention of the writer
> are better than "idioms" which are only so because the library did not
> include a function to start with. Not to mention that optimizers are
> not magical, plus it takes build time to untangle the mess anyway.

But isn't that what `get_if` does already? It is a simple API, and a
proper one. It reflects the intent of the writer. It's not an idiom;
it's how you get a value from a `variant`.

As it stands, we have two ways to extract a value from a variant. I
don't believe we need *three* ways to do it.

Received on 2020-10-27 10:43:06