There's a newer version of std::getline with C++11. It accepts a rvalue "input"-parameter. But why there is a rvalue-parameter, i.e. the fuction would consume the "input"-parameter, leaving the input-parameter empty after the call ?
There's a newer version of std::getline with C++11. It accepts a rvalue "input"-parameter. But why there is a rvalue-parameter, i.e. the fuction would consume the "input"-parameter, leaving the input-parameter empty after the call ?
I imagine it's for code where the stream is constructed as part of the call to getline, e.g
std::string s = ...;
std::string s2;
getline(std::istringstream(s), s2);
This code would take the first line from s and put it in s2, for instance.
Code like this would not be legal with the older version of getline because the first parameter of that is a non-const reference.