C++ Logo

std-discussion

Advanced search

Re: Vector implementation of behavior when inserting objects whose copy constructor can throw

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Tue, 27 Jul 2021 23:49:08 +0300
On 7/27/21 10:59 PM, Brian Bi via Std-Discussion wrote:
>
> Anyway, I don't think that swapping is actually a valid implementation
> strategy. What if swap(T&, T&) has observable effects besides swapping
> the two objects? Is std::vector<T>::insert allowed to produce those effects?

According to standard requirements for the customization points, any
user-defined customizations must implement the same behavior as defined
by the standard. IOW, the standard can rely that user's overloads of
swap() will have the effect of swapping the two values, and can use that
effect in its implementation.

Whether there are any other side effects is irrelevant. Same as with
user-defined constructors and assignment - those functions may also have
side effects that are beside just copying the object, and those side
effects are allowed to occur.

Received on 2021-07-27 15:49:13