Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for a snapshot of the develop branch, built from commit c5994560ca.
PrevUpHomeNext

Class template old_ptr

boost::contract::old_ptr — Old value pointer that requires the pointed old value type to be copyable.

Synopsis

// In header: <boost/contract/old.hpp>

template<typename T> 
class old_ptr {
public:
  // types
  typedef T element_type;  // Pointed old value type. 

  // construct/copy/destruct
  old_ptr();

  // public member functions
  T const  & operator *() const;
  T const  * operator->() const;
  explicit operator bool() const;
};

Description

This pointer can be set to point an actual old value copy using either BOOST_CONTRACT_OLDOF or boost::contract::make_old (that is why this class does not have public non-default constructors):

class u {
public:
    virtual void f(..., boost::contract::virtual_* v = 0) {
        boost::contract::old_ptr<old_type> old_var = // For copyable `old_type`.
                BOOST_CONTRACT_OLDOF(v, old_expr);
        ...
    }

    ...
};

See Also:

Old Values

Template Parameters

  1. typename T

    Type of the pointed old value. This type must be copyable (i.e., boost::contract::is_old_value_copyable<T>::value must be true), otherwise this pointer will always be null and this library will generate a compile-time error when the pointer is dereferenced.

old_ptr public construct/copy/destruct

  1. old_ptr();
    Construct this old value pointer as null.

old_ptr public member functions

  1. T const  & operator *() const;
    Dereference this old value pointer.

    This will generate a run-time error if this pointer is null and 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:

    The pointed old value. Contract assertions should not change the state of the program so this member function is const and it returns the old value as a reference to a constant object (see Constant Correctness).

  2. T const  * operator->() const;
    Structure-dereference this old value pointer.

    This will 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 const and it returns the old value as a pointer to a constant object (see Constant Correctness).

  3. explicit operator bool() const;
    Query 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.


PrevUpHomeNext