This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [PATCH] Optimize inserting value_type into std::vector
- From: FranÃois Dumont <frs dot dumont at gmail dot com>
- To: Jonathan Wakely <jwakely at redhat dot com>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Sun, 19 Jun 2016 10:21:27 +0200
- Subject: Re: [PATCH] Optimize inserting value_type into std::vector
- Authentication-results: sourceware.org; auth=none
- References: <20160615101511 dot GN11538 at redhat dot com> <20160615103424 dot GO11538 at redhat dot com> <5762FDAC dot 5000802 at gmail dot com> <20160616202106 dot GB11538 at redhat dot com>
On 16/06/2016 22:21, Jonathan Wakely wrote:
On 16/06/16 21:27 +0200, François Dumont wrote:
Very nice improvement. Could also benefit to other containers,
especially std::deque. Do you plan to take care of it ?
Good point - I'd only looked at it for std::vector, because that's
what Howard's experiment tested. I haven't looked at the other
containers at all, and wasn't planning to do so. If you have time to
look at them that would be great, otherwise I'll add it to my TODO
list for something to look at later.
I started considering it and so came to the question of insert/emplace
of the container self values. Is the following program ill-formed ?
int main()
{
std::vector<std::vector<int>> vv =
{
{ 2, 3 },
{ 4, 5 },
{ 0, 1 }
};
vv.reserve(4);
vv.emplace(vv.begin(), vv[0]);
assert( vv[0].size() == 2 );
}
The assert fails because we end-up assigning a moved vector instance to
vv first entry. This is not a regression of this patch, we were already
not creating any copy before moving all vector values. If this program
is ill-formed why does libc++ consider this kind of situation in its
insert implementation ?
Note that it gave me the idear of adding a DEBUG check detecting when a
moved instance is being used. A moved instance shall only be destroyed
or assigned, no ? Maybe only in pedantic mode ?
François