On Sun, 21 Sep 2003 20:39:06 -0400, "Marcin Vorbrodt"
<mv*****@eos.ncsu.edu> wrote:
A source function is a one that returns an auto_ptr object. A sink function
is one that takes auto_ptr as a parameter. So:
void Source(auto_ptr<SomeClass> aptr);
This will transfer the ownership correctly. How about this:
void Source(auto_ptr<SomeClass> & aptr);
Passing it as reference (non-const) should still do the trick, right?
Is there an advantage to doing so? Speed-wise I mean?
It is probably marginally faster (depending on optimization settings),
but it is no longer explicit. e.g.
void Sink(auto_ptr<SomeClass> & aptr)
{
aptr.reset(new SomeClass);
//actually a source!
}
This obviously isn't possible if you pass by value, so the parameter
is a proper sink. In addition, you can pass temporary auto_ptrs by
value. e.g.
//illegal for reference version:
Sink(auto_ptr<SomeClass>(new SomeClass));
Tom