C++ Logo


Advanced search

Re: Thoughts on making unchecked_emplace_back a public function for vector?

From: Lénárd Szolnoki <cpp_at_[hidden]>
Date: Mon, 11 Oct 2021 21:21:55 +0100

In a recent proposal vector will gain range construction and append operations. This will allow safely expressing operations that would otherwise require unchecked_emplace_back.

For example a reserve + push_back loop can be replaced by an append with a sized input range. The vector can internally reserve once based on the size, then it can do the equivalent of unchecked_emplace_back in a loop.


-------- Original Message --------
From: Victor Khomenko via Std-Discussion <std-discussion_at_[hidden]>
Sent: October 11, 2021 2:19:59 PM GMT+01:00
To: "std-discussion_at_[hidden]" <std-discussion_at_[hidden]>
Cc: Victor Khomenko <victor.khomenko_at_[hidden]>, Alex <orangechicken_at_[hidden]>
Subject: Re: [std-discussion] Thoughts on making unchecked_emplace_back a public function for vector?

[It's best to use std-proposals list as you're trying to propose a new feature (this list is mostly about the current standard, things like wording/defects).]

I tried to propose something similar back in 2013, see the discussion here:

In the course of the discussion, push_back_ was (sensibly) renamed into unchecked_push_back.

My feeling was that people generally disliked this idea, so I didn't get to writing a proposal.

All the best,

> -----Original Message-----
> From: Std-Discussion <std-discussion-bounces_at_[hidden]> On Behalf Of
> Alex via Std-Discussion
> Sent: Monday, October 11, 2021 1:53 PM
> To: std-discussion_at_[hidden]
> Cc: Alex <orangechicken_at_[hidden]>
> Subject: [std-discussion] Thoughts on making unchecked_emplace_back a public
> function for vector?
> ⚠ External sender. Take care when opening links or attachments. Do not
> provide your login details.
> I've been playing around with a slightly modified version of the standard vector
> header for a while now which makes "unchecked_emplace_back" a usable
> function as well as some other utility functions I've added. There's more than a
> few cases I've had so far to use it and net a bit of a bonus bit of performance.
> Rough idea is a function (or functions) which assumes a bit more responsibility
> on the side of the user, but it short cuts some redundant checks on the
> containers capacity. In playing around I actually found a different way to go
> about this which was way faster, however I think it might be a stretch because it
> would pretty much allow full access over all the vector's members.
> The only thing I'm really wondering is whether this is the right email to send this
> to, some places suggested floating standards proposals here, wasn't exactly
> clear. In any case, thoughts? The edits for reference to existing headers are
> extremely minor, usually because an unchecked version of emplace_back is
> already written as a utility function for emplace_back to work. I also have zero
> reference for whether this has been brought up before.
> --
> -Alex Anderson
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.isoc
> pp.org%2Fmailman%2Flistinfo.cgi%2Fstd-
> discussion&amp;data=04%7C01%7CVictor.Khomenko%40newcastle.ac.uk%7C1
> 083a8dbe3e2497ee18408d98cb6179d%7C9c5012c9b61644c2a91766814fbe3e8
> 7%7C1%7C0%7C637695535972721267%7CUnknown%7CTWFpbGZsb3d8eyJWIj
> oiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C100
> 0&amp;sdata=XNbzAnK4do%2BjVHDGNL6lFGuwZqodJ6EmAhj5q8MCvoo%3D&a
> mp;reserved=0
Std-Discussion mailing list

Received on 2021-10-11 15:25:23