On Thu, Apr 4, 2019 at 3:14 PM Gavin Lambert via Boost < boost@lists.boost.org> wrote:
On 4/04/2019 13:26, Emil Dotchevski wrote:
Consistent with the basic guarantee, if you assign one std::vector to another and the copy operation fails, the contents of the target vector
is
not specified, but it is guaranteed to be a valid vector, so that if you happen to handle it later, you can safely do with it what you do with any other vector: you can insert or delete elements, iterate, whatever.
By analogy with your position, a better design for std::vector would be to define a special "error" state that you must check for *every* time you handle a vector, and the justification for that design is that otherwise it might be unexpected to see a vector in a half-copied (but valid, by definition) state. Do you see the practical difference now?
No, because vector already has that state -- it's called "a vector with size zero" (aka "empty"), which is the same state it typically transitions to when successfully moved-from.
template <class T> void f( std::vector<T> & x, std::vector<T> const & y ) { x = y; } Above, if the assignment fails, the content of x is unspecified, but it is guaranteed to be a valid vector, containing valid objects (if not empty). By analogy: if a variant2 assignment fails, its value is unspecified, but it is guaranteed to be valid.