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 an old version of Boost. Click here to view this page for the latest version.
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  *const operator->() const;
  explicit operator bool() const;
};

Description

This is set to point to 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 =
                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 is 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  *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 constant pointer to a constant object (see Constant Correctness).

  3. explicit operator bool() const;
    Check if this old value pointer is null or not.

    (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