[PATCH v2] libstdc++: Add std::inplace_vector for C++26 (P0843R14) [PR119137]

Jonathan Wakely jwakely@redhat.com
Thu Jul 17 20:38:56 GMT 2025


On 17/07/25 15:23 -0400, Patrick Palka wrote:
>On Thu, 17 Jul 2025, Tomasz Kamiński wrote:
>> +      constexpr inplace_vector&
>> +      operator=(const inplace_vector& __other)
>> +      noexcept(is_nothrow_copy_assignable_v<_Tp>
>> +		 && is_nothrow_copy_constructible_v<_Tp>)
>> +      {
>> +	assign(__other.begin(), __other.end());
>
>Do we need to worry about self-assignment here?  IIUC it's a
>precondition violation to call assign with an iterator into the
>container being assigned to.  LGTM other than that.

Good question. It will actually work fine for self-assignment; we
don't enforce the precondition.  We'll just loop over the elements and
do self-assignment for each one. That's wasteful, but not wrong
(assuming the elements themselves are safe for self-assignment).

It would be more efficient to not do that loop though, and the check
for `if (addressof(__other) == this)` can be marked [[unlikely]].






More information about the Libstdc++ mailing list