
18 Feb
2009
18 Feb
'09
10:16 p.m.
Emil Dotchevski wrote:
And what if I write my own class outer_bar that owns bar and also want to be ostreamable? I would have to duplicate my operator<< in order to call either to_string or to_wstring, wouldn't I?
No.
You can define template operator<<
How is that?
or you can define non-template std::string overload of operator<< only. The user would still be able to call to_wstring, which will bind to a wstring overload if it's available. If not, the generic to_wstring overload will call the std::string operator<< overload, and then convert the result to wstring.
But I will lose generic ostreamability for my class then. Sorry, I just don't see any advantages for differently named functions.