I have a similar follow up question about returning a std::tuple<ve0, vec1, vec2, vec3, ....>.
Suppose a game class have several member vectors:
class Game
{
public:
Game();
~Game();
std::tuple<
std::vector<std::string>, // vec0
std::vector<std::string>, // vec1
std::vector<std::string>, // vec2
std::vector<std::string> // vec3
> takeOutput();
private:
//Wrap members in m_output?
//std::tuple<
std::vector<std::string> m_vec0;
std::vector<std::string> m_vec1;
std::vector<std::string> m_vec2;
std::vector<std::string> m_vec3;
//> m_output
}
The game class has a method to take out these vectors called std::tuple<....> takeOutput():
std::tuple<
std::vector<std::string>, // vec0
std::vector<std::string>, // vec1
std::vector<std::string>, // vec2
std::vector<std::string> // vec3
> Game::takeOutput()
{
return m_output; // returns a copy? I want to move it out
//? return std::move(m_output);
//std::swap(localTuple, m_output) return localTuple; //swap method with a local, disables RVO?
//? return std::make_tuple(m_vec0, m_vec1, m_vec2, m_vec3);
//? return std::make_tuple(std::move(m_vec0), std::move(m_vec1), std::move(m_vec2), std::move(m_vec3));
}
I believe std::tuple has move semantics built in. But how would I go about wrapping the vectors in the tuple before returning from takeOutput()?
Should I have a member std::tuple<...> m_output and return it, possibly using std::swap or std::move?
Or should I return r-value using std::make_tuple<...>(vec0, vec1, vec2, vec3....)? What about std::move to move vectors into tuple?