Gianni Mariani wrote:
> vector<int> f()
> {
> vector<int> xxx;
> return xxx;
> }
> (rather an expensive operation if the vector is big however!)
Only if your compiler does not do NRVO. The standard allows optimising the copy away.
Unfortunately only a few compilers do this, and because of this in a general case I prefer
template<class OutIt>
void f(OutIt out)
{
// (for example std::copy(begin, end, out))
}
std::vector<int> v;
f(std::back_inserter(v));
This will always avoid the extra copy of the vector, no matter how good your compiler is.
--
Valentin Samko -
http://www.valentinsamko.com