|
From: Luigi B. <lui...@gm...> - 2006-05-17 08:22:21
|
On 05/16/2006 07:52:59 PM, DU VIGNAUD Fran=E7ois wrote:
> The following constructor destroys
> the non disposable object t given as argument:
> (ql/Utilities/disposable.hpp)
>=20
> 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 =20
Disposable<Foo> implied by the return. The problem was that it is =20
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 =20
should take, nor of their types. Other approaches might be possible, =20
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
|