Ralf Fassel
2015-09-23 13:27:48 UTC
Having not understood completely and absolutely in all depth the concept
of rvalue references, I hope the following is not an FAQ...
My understanding was that after an move operation on an object, one
should not further deal with it:
#include <vector>
#include <string>
#include <sstream>
void split_string(const std::string & s, std::vector<std::string> & v) {
std::istringstream sstrm(s);
std::string str;
// here we're reusing str after the emplace_back, is this ok?
while(sstrm >> str) v.emplace_back(str);
}
Should this loop better be
while (1) {
std::string str;
if (!(sstrm >> str)) break;
v.emplace_back(str);
}
Somehow I feel that the >> operator in the first example could do
nothing worse than the DTOR in the second, so both should be ok?
TNX
R'
of rvalue references, I hope the following is not an FAQ...
My understanding was that after an move operation on an object, one
should not further deal with it:
#include <vector>
#include <string>
#include <sstream>
void split_string(const std::string & s, std::vector<std::string> & v) {
std::istringstream sstrm(s);
std::string str;
// here we're reusing str after the emplace_back, is this ok?
while(sstrm >> str) v.emplace_back(str);
}
Should this loop better be
while (1) {
std::string str;
if (!(sstrm >> str)) break;
v.emplace_back(str);
}
Somehow I feel that the >> operator in the first example could do
nothing worse than the DTOR in the second, so both should be ok?
TNX
R'
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]