I want to call a function that constructs a stringstream
object and if some condition is met, invalidate the stringstream
. When I try this, I get a warning from using a moved from object. How can I prevent this without switching to a string
?
#include <iostream>
#include <sstream>
#include <functional>
using namespace std;
bool Condition(string) { return true; }
stringstream someFunc(function<bool(string&)> Condition) {
stringstream ssRes; // Warning C26800 Use of a moved from object:'ssRes'
ssRes << "here is a string";
string str = ssRes.str();
if (!Condition(str)) { ssRes.setstate(ios_base::failbit); }
return ssRes;
}
int main() {
stringstream ss = someFunc(Condition);
return 0;
}