c++ - Does returning a standard container incur a copy of the contents of the container? -
if have function returns stl container incurring copy of entire contents of standard container?
e.g. this:
void foo( std::vector< std::string >* string_list );
better this:
std::vector< std::string > foo();
does matter what's in container? instance returning container this:
struct buzz { int a; char b; float c; } std::map< int, buzz > foo();
be more costly operation this:
std::map< int, int > foo();
thanks, paulh
edit: c++03. c++0x solution is, unfortunately, not acceptable.
edit2: using microsoft visual studio 2008 compiler.
c++03 (named) return value optimization (google rvo , nrvo).
if optimization not applicable, c++0x move semantics.
Comments
Post a Comment