Logo Search packages:      
Sourcecode: quantlib version File versions  Download package

QuantLib::Disposable< T > Class Template Reference

generic disposable object with move semantics More...

#include <disposable.hpp>

List of all members.

Public Member Functions

 Disposable (T &t)
 Disposable (const Disposable< T > &t)
Disposable< T > & operator= (const Disposable< T > &t)

Detailed Description

template<class T>
class QuantLib::Disposable< T >

generic disposable object with move semantics

This class can be used for returning a value by copy. It relies on the returned object exposing a swap(T&) method through which the copy constructor and assignment operator are implemented, thus resulting in actual move semantics. Typical use of this class is along the following lines:

        Disposable<Foo> bar(Integer i) {
            Foo f(i*2);
            return f;
        }
Warning:
In order to avoid copies in code such as shown above, the conversion from T to Disposable<T> is destructive, i.e., it does not preserve the state of the original object. Therefore, it is necessary for the developer to avoid code such as
        Disposable<Foo> bar(Foo& f) {
            return f;
        }
which would likely render the passed object unusable. The correct way to obtain the desired behavior would be:
        Disposable<Foo> bar(Foo& f) {
            Foo temp = f;
            return temp;
        }

Definition at line 64 of file disposable.hpp.


The documentation for this class was generated from the following file:

Generated by  Doxygen 1.6.0   Back to index