|
Boost : |
Subject: Re: [boost] [contract] move operations and class invariants
From: Peter Dimov (lists_at_[hidden])
Date: 2017-11-29 14:15:16
Lorenzo Caminiti wrote:
> C++ requires that moved-from objects can still be destructed. Because
> contract programming requires class invariants to hold at destructor
> entry, it follows that moved-from objects must still satisfy class
> invariants.
No, moved-from objects must be valid objects. Not only can they be
destroyed, they must be usable. Their state is unspecified, but invariants
hold.
> That sounds restrictive... and it might force the class invariants to be
> empty. For example, for vector a class invariant is size() <= capacity().
> Should that sill hold after the vector has been moved?
Yes.
> That means I can still call size() and capacity() on a moved-from object,
> which might not be the case.
No. You must be able to call size() and capacity().
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk