I have a simple class:
class X
{
std::string S;
X (const std::string& s) : S(s) { }
};
I've read a bit about rvalues lately, and I've been wondering, if I should write constructor for X
using rvalue, so I would be able do detect temporary objects of std::string
type?
I think it should look something like:
X (std::string&& s) : S(s) { }
As to my knowledge, implementation of std::string in compilers supporting C++11 should use it's move constructor when available.
See Question&Answers more detail:os