I have a function which produces a type of expensive object (containing vectors and a maps of a non fixed size) so I really want to avoid invoking copy c'tors.
Until now I have just returned a std::shared_ptr from the method and used that but I think it is ugly and requires typedeffing to be really usuable.
I am aware of two thing that may help me. Firstly copy elision and the second is the move semantic.
My problem is that I know how to use neither properly. My research has told me that copy elision is entirely done by compiler and is not apart of the st'd. I don't really want to have to solely rely on this.
So how do I ensure that move assigment is invoked and does having it in place going to prevent the compiler from doing to copy elision.
ResultSet &&generateResults()
{
//ResultSet a(); :S
ResultSet a;
a.populat(...
//blah blah blah
return a;
}
//else where (where the && assignment operator is overloaded
ResultsSet b = generateResults();
In this case is this the most correct way to code this? and if not how could I improve it. I am happy to use C++0x only constructs.
BTW: My compiler is gcc 4.6