...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::contract::old_value_copy — Trait to copy an old value.
// In header: <boost/contract/old.hpp> template<typename T> struct old_value_copy { // construct/copy/destruct explicit old_value_copy(T const &); // public member functions T const & old() const; };
By default, the implementation of this trait uses T's
copy constructor to make one single copy of the specified value
. However, programmers can specialize this trait to copy old values using user-specific operations different from T's
copy constructor. The default implementation of this trait is equivalent to:
template<typename T> class old_value_copy { public: explicit old_value_copy(T const& old) : old_(value) // One single copy of value using T's copy constructor. {} T const& old() const { return old_; } private: T const old_; // The old value copy. };
This library will instantiate and use this trait only on old value types T
that are copyable (i.e., for which boost::contract::is_old_value_copyable<T>::value
is true
).
See Also:
old_value_copy
public
construct/copy/destructexplicit old_value_copy(T const & old);Construct this object by making one single copy of the specified old value.
This is the only operation within this library that actually copies old values. This ensures this library makes one and only one copy of old values (if they actually need to be copied).
Parameters: |
|
old_value_copy
public member functionsT const & old() const;Return a (constant) reference to the old value that was copied.
Contract assertions should not change the state of the program so the old value copy is returned as const
(see
Constant Correctness).