Files
gcc/libstdc++-v3/doc/doxygen
Jonathan Wakely 9e33097738 libstdc++: Add std::inplace_vector for C++26 (P0843R14) [PR119137]
Implement std::inplace_vector as specified in P0843R14, without follow
up papers, in particular P3074R7 (trivial unions). In consequence
inplace_vector<T, N> can be used inside constant evaluations only
if T is trivial or N is equal to zero.

We provide a separate specialization for inplace_vector<T, 0> to meet
the requirements of N5008 [inplace.vector.overview] p5. In particular
objects of such types needs to be empty.

To allow constexpr variable of inplace_vector v, where v.size() < v.capacity(),
we need to guaranteed that all elements of the storage array are initialized,
even ones in range [v.data() + v.size(), v.data() + v.capacity()). This is
perfoirmed by _M_init function, that is called by each constructor. By storing
the array in anonymous union, we can perform this initialization in constant
evaluation, avoiding the impact on runtime path.

The size() function conveys the information that _M_size <= _Nm to compiler,
by calling __builtin_unreachable(). In particular this allows us to eliminate
FP warnings by using _Nm - size() instead of _Nm - _M_size, when computing
available elements.

The included test cover almost all code paths at runtime, however some
compile time evaluation test are not yet implemented:
* operations on range, they depend on making testsuite_iterators constexpr
* negative test for invoking operations with preconditions at compile time,
  especially for zero size specialization.

	PR libstdc++/119137

libstdc++-v3/ChangeLog:

	* doc/doxygen/user.cfg.in (INPUT): Add new header.
	* include/Makefile.am: Add new header.
	* include/Makefile.in: Regenerate.
	* include/bits/stl_iterator_base_types.h (__any_input_iterator):
	Define.
	* include/bits/version.def (inplace_vector): Define.
	* include/bits/version.h: Regenerate.
	* include/precompiled/stdc++.h: Include new header.
	* src/c++23/std.cc.in: Export contents if new header.
	* include/std/inplace_vector: New file.
	* testsuite/23_containers/inplace_vector/access/capacity.cc: New file.
	* testsuite/23_containers/inplace_vector/access/elem.cc: New file.
	* testsuite/23_containers/inplace_vector/access/elem_neg.cc: New file.
	* testsuite/23_containers/inplace_vector/cons/1.cc: New file.
	* testsuite/23_containers/inplace_vector/cons/from_range.cc: New file.
	* testsuite/23_containers/inplace_vector/cons/throws.cc: New file.
	* testsuite/23_containers/inplace_vector/copy.cc: New file.
	* testsuite/23_containers/inplace_vector/erasure.cc: New file.
	* testsuite/23_containers/inplace_vector/modifiers/assign.cc: New file.
	* testsuite/23_containers/inplace_vector/modifiers/erase.cc: New file.
	* testsuite/23_containers/inplace_vector/modifiers/multi_insert.cc:
	New file.
	* testsuite/23_containers/inplace_vector/modifiers/single_insert.cc:
	New file.
	* testsuite/23_containers/inplace_vector/move.cc: New file.
	* testsuite/23_containers/inplace_vector/relops.cc: New file.
	* testsuite/23_containers/inplace_vector/version.cc: New file.
	* testsuite/util/testsuite_iterators.h (input_iterator_wrapper::base):
	Define.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Co-authored-by: Tomasz Kamiński <tkaminsk@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
2025-07-18 09:49:34 +02:00
..
2025-01-02 11:59:57 +01:00