I read a couple of posts on how to return a vector from a method include these ones:
and I'm still confused on how to pass a vector the right way in VS2013 and what are the differences between the following methods in this code(the questions are marked in the comments):
class Foo{
private:
std::vector<int> vect;
public:
//1 - classic way?
void GetVect(std::vector<int>& v)
{
v = vect;// assignment with swap?
}
//2 - RVO?
std::vector<int> GetVect()
{
return vect;
}
//3 - RVO with const?
std::vector<int> GetVect() const
{
return vect;
}
//4 - just move?
std::vector<int> GetVect()
{
return std::move(vect);
}
//5 - move with {}?
std::vector<int> GetVect()
{
return { std::move(vect) };
}
}
So I m not sure if //1 is an explicit form of //2, not sure if 3 works. What are the differences between 4 and 5? How to test it if RVO works for vectors in VS2013?