Consider the following code:
class StringTokanizer
{
private:
char m_delimiter;
std::istringstream m_string;
public:
explicit StringTokanizer(const std::string& str, char delimiter) : m_string(str), m_delimiter(delimiter) { }
template <class Container>
operator Container ()
{
Container container;
for (std::string token; std::getline(m_string, token, m_delimiter); )
{
container.insert(container.end(), token);
}
return container;
}
};
This is the usage:
vector<string> tmp = StringTokanizer("123 456", ' ');
When debugging the following happens:
At the return
statement of conversion operator
- new vector constructed from
container
by moving container
gets destructed
After function return:
tmp
is constructed by copy constructor
My question is why isn't tmp
constructed by move constructor ?
As I understand things function return type is rvalue and should be moved.
Aucun commentaire:
Enregistrer un commentaire