Re: QuEP 4: Reducing abstraction penalty by means of disposable arrays
Posted by Luigi Ballabio on May 17, 2006; 2:23am
URL: http://quantlib.414.s1.nabble.com/QuEP-4-Reducing-abstraction-penalty-by-means-of-disposable-arrays-tp11132p11133.html
On 05/16/2006 07:52:59 PM, DU VIGNAUD François wrote:
> The following constructor destroys
> the non disposable object t given as argument:
> (ql/Utilities/disposable.hpp)
>
> template <class T>
> inline Disposable<T>::Disposable(T& t) {
> this->swap(t);
> }
Yes, this is by design. The purpose is to allow one to write
Disposable<Foo> bar() {
Foo f(1,2);
return f;
}
and avoid the copy in the automatic conversion from Foo to
Disposable<Foo> implied by the return. The problem was that it is
difficult to initialize a Disposable directly, as in:
Disposable<Foo> baz() {
Disposable<Foo> f(1,2);
return f;
}
because Disposable has no idea of how many arguments the constructor
should take, nor of their types. Other approaches might be possible,
but I think they make the resulting client code more clumsy.
Luigi
----------------------------------------
The first rule of intelligent tinkering is to save all the parts.
-- Paul Erlich