Yes, it was about move semantics. Here's a better way of rephrasing the question. The code below compiles but gives a runtime crash.
The way to fix this is to delete the && from std::vector<std::string> && tmp = ...
My question is why this fix is necessary. Why doesn't the code below do the swap? Thank you very much for your help.
Paul
void swap( std::vector<std::string> & x, std::vector<std::string> & y )
{
std::vector<std::string>&& tmp = static_cast<std::vector<std::string> &&>( x );
x = static_cast<std::vector<std::string> &&>( y );
y = static_cast<std::vector<std::string> &&>( tmp );
}
int main()
{
std::vector<std::string> vecStr1{"hello", "world"};
std::vector<std::string> vecStr2{"heh", "one"};
swap(vecStr1, vecStr2);
std::cout<<vecStr1[0];
}