gcc/libstdc++-v3/testsuite/backward
Tomasz Kamiński 390f3a690c libstdc++: Do not require assignment for vector::resize(n, v) [PR90192]
This patch introduces a new function, _M_fill_append, which is invoked when
copies of the same value are appended to the end of a vector. Unlike
_M_fill_insert(end(), n, v), _M_fill_append never permute elements in place,
so it does not require:
* vector element type to be assignable;
* a copy of the inserted value, in the case where it points to an
  element of the vector.

vector::resize(n, v) now uses _M_fill_append, fixing the non-conformance where
element types were required to be assignable.

In addition, _M_fill_insert(end(), n, v) now delegates to _M_fill_append, which
eliminates an unnecessary copy of v when the existing capacity is used.

	PR libstdc++/90192

libstdc++-v3/ChangeLog:

	* include/bits/stl_vector.h (vector<T>::_M_fill_append): Declare.
	(vector<T>::fill): Use _M_fill_append instead of _M_fill_insert.
	* include/bits/vector.tcc (vector<T>::_M_fill_append): Define
	(vector<T>::_M_fill_insert): Delegate to _M_fill_append when
	elements are appended.
	* testsuite/23_containers/vector/modifiers/moveable.cc: Updated
	copycount for inserting at the end (appending).
	* testsuite/23_containers/vector/modifiers/resize.cc: New test.
	* testsuite/backward/hash_set/check_construct_destroy.cc: Updated
	copycount, the hash_set constructor uses insert to fill buckets
	with nullptrs.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-08-26 18:18:32 +02:00
..
hash_map
hash_set libstdc++: Do not require assignment for vector::resize(n, v) [PR90192] 2025-08-26 18:18:32 +02:00
11460.cc
strstream_members.cc
strstream_move.cc