| Home | Libraries | People | FAQ | More

## Struct template old_value_copy

boost::contract::old_value_copy — Trait to copy an old value.

## Synopsis

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

    template<typename T>
    struct old_value_copy {

      // public member functions
      explicit old_value_copy(T const &);
      T const & old() const;
    };

## Description

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_(old) // 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 Requirements

### `old_value_copy` public member functions

1.     explicit 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 an old value (if they actually need to be copied, see ``BOOST_CONTRACT_NO_OLDS``).

   Parameters: |
   `old` | The old value to copy.

2.     T 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).