I have a class that wraps around std::string
to provide formatting:
struct Wrap {
std::string& s; // need const ref for output, non const for input
friend std::ostream& operator<< (std::ostream& os, const Wrap& w) {
os << "[" << w.s << "]";
return os;
}
friend std::istream& operator>> (std::istream& is, Wrap&& w) {
Is >> ......;
return is;
}
};
And it's ok with output:
my_ostream << Wrap{some_string};
Because binding the temp Wrap to const ref is ok.
But less ok with input:
my_istream >> Wrap{some_string}; // doesn't compile - cannot bind lvalue to rvalue
I probably make it build but since I have not seen any >> &&
something doesn't feel right.
Is >>&&
forbidden or evil in some way?