C++ Logo

std-proposals

Advanced search

Re: std::as

From: Ryan P. Nicholl <rnicholl_at_[hidden]>
Date: Tue, 27 Oct 2020 21:29:13 +0000
Have you looked much at the number of different ways you can insert things into a vector? :D

I think "not having another way to do something" is a poor argument, given existing precedent for basically the entire STL having on average two dozen overloads for each function. (OK, maybe not that many, but I hope you get the point.)

v = vector<int>();
v = vector<int>{};
v.clear();
v.erase(v.begin(), v.end());
v = {};
v.resize(0);

All do the same thing, with subtly different meanings.

We have .push_back(...) even though we can .insert(...) at the end.

etc. etc.

Some languages like the "one true way" methodology. C++ has never adopted that language philosophy. Nor should we adopt it now. It conflicts with the C++ goal of being multi-paradigm.

--
Ryan P. Nicholl
Tel: (678)-358-7765
Personal Email: rnicholl_at_[hidden]
Work Email: ryan.nicholl_at_[hidden]
Tox: 52B3A61CDAF88BCC854F568933F071E3530600CDBA3D5354AADC9AD179575D68021AE959719D
-------- Original Message --------
On Oct 27, 2020, 11:42, Jason McKesson via Std-Proposals wrote:
> On Tue, Oct 27, 2020 at 6:16 AM Miguel Ojeda via Std-Proposals
> <std-proposals_at_lists.isocpp.org> wrote:
>>
>> On Mon, Oct 26, 2020 at 8:18 PM Arthur O'Dwyer via Std-Proposals
>> <std-proposals_at_lists.isocpp.org> 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.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2020-10-27 16:29:26