I have a Text class that contain a std::string. A method SetText as follow :
void Text::SetText( const std::string& str )
{
m_str = str;
}
Since this method will almost always been called with rvalues as parameter, I thought about move constructors. I understand the basics, but that's all. So I made tests and came to the conclusion that another function like that would be better, and once the move constructor and move assignement were defined, there could be performance gains :
void Text::SetText( std::string&& str )
{
m_str = move( str );
}
There are my questions :
- Does it works with std container? Does they provide move constructor and assignements?
- Is move semantics usefull when there is not heap allocations is the class ? ( I mean no heap allocation at all, so no smart pointers as class member )
Thanks.