...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_ptr_if_copyable — Old value pointer that does not require the pointed old value type to be copyable.
// In header: <boost/contract/old.hpp> template<typename T> class old_ptr_if_copyable { public: // types typedef T element_type; // Pointed old value type. // construct/copy/destruct old_ptr_if_copyable(); old_ptr_if_copyable(old_ptr< T > const &); // public member functions T const & operator*() const; T const *const operator->() const; explicit operator bool() const; };
This is set to point to an actual old value copy using either BOOST_CONTRACT_OLDOF
or boost::contract::make_old
:
template<typename T> // Type `T` might or not be copyable. class u { public: virtual void f(..., boost::contract::virtual_* v = 0) { boost::contract::old_ptr_if_copyable<T> old_var = BOOST_CONTRACT_OLDOF(v, old_expr); ... if(old_var) ... // Always null for non-copyable types. ... } ... };
See Also:
typename T
Type of the pointed old value. If this type is not copyable (i.e., boost::contract::is_old_value_copyable<T>::value
is false
), this pointer will always be null (but this library will not generate a compile-time error when this pointer is dereferenced).
old_ptr_if_copyable
public
construct/copy/destructold_ptr_if_copyable();Construct this old value pointer as null.
old_ptr_if_copyable(old_ptr< T > const & other);Construct this old value pointer from an old value pointer that requires the old value type to be copyable.
This constructor is implicitly called by this library when assigning an object of this type using
(this constructor is usually not explicitly called by user code).BOOST_CONTRACT_OLDOF
Parameters: |
|
old_ptr_if_copyable
public member functionsT const & operator*() const;Dereference this old value pointer.
This will generate a run-time error if this pointer is null, but no compile-time error is generated if the pointed type T
is not copyable (i.e., if boost::contract::is_old_value_copyable<T>::value
is false
).
Returns: |
The pointed old value. Contract assertions should not change the state of the program so this member function is |
T const *const operator->() const;Structure-dereference this old value pointer.
This will return null but will not generate a compile-time error if the pointed type T
is not copyable (i.e., if boost::contract::is_old_value_copyable<T>::value
is false
).
Returns: |
A pointer to the old value (null if this old value pointer is null). Contract assertions should not change the state of the program so this member function is |
explicit operator bool() const;Check if this old value pointer is null or not (safe-bool operator).
(This is implemented using safe-bool emulation on compilers that do not support C++11 explicit type conversion operators.)
Returns: |
True if this pointer is not null, false otherwise. |