I thought that to_string
was just templatized and used stringstream
under the hood.
Is that not the case?
I want to be able to do this:
class foo{};
ostream& operator<<(ostream& os, const foo& /*bar*/){
os << "foo";
return os;
}
int main() {
foo bar;
string tsTest = to_string(bar);
return 0;
}
But obviously that doesn't work cause to_string
isn't templatized.
No, to_string is not for any type. There are only overloads for primitive standard types. It's not replace of boost::lexical_cast
unfortunately.