Anton Bachin wrote:
On Jun 12, 2015, at 05:51, Peter Dimov wrote:
Streams are already templated, so artificial templating shouldn't be
necessary if you use basic_istream and basic_ostream.
But the compiler is able to instantiate those eagerly if a type argument
is specified (char) that does not depend on the outer template parameter.
It is. What I meant was:
template
inline std::basic_ostream&
operator <<(std::basic_ostream& os, const Enum& value)
{
return os << value.template _to_basic_string<Ch>();
}
You'll have to define _to_basic_string for char, wchar_t, char16_t and
char32_t if you want to cover all cases, of course.
If you want to restrict yourself to char-based streams:
template
inline std::basic_ostream&
operator <<(std::basic_ostream& os, const Enum& value)
{
return os << value._to_string();
}
although it's better to handle at least wchar_t as well.