If I use auto_ptr as the return value of a function that fills large vectors, this makes the function the original function (it will create an internal auto_ptr and transfer ownership when it returns not const const_ppt). However, I cannot use this function with STL algorithms because I need to split auto_ptr to access the data. A good example, I think, would be a field of vectors of size N, with each vector having 100 components. The Wether function returns every 100 components of a vector by value or by ref is not the same if N is large.
Also, when I try this very basic code:
class t
{
public:
t() { std::cout << "ctor" << std::endl; }
~t() { std::cout << "dtor" << std::endl; }
};
t valueFun()
{
return t();
}
std::auto_ptr<t> autoFun()
{
return std::auto_ptr(new t());
}
and autoFun and fun calls are output
CTOR Dtor
, return. , valueFun? Does valueFun ?
?