
Anton Bachin wrote:
On Jun 12, 2015, at 05:51, Peter Dimov <lists@pdimov.com> 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 <class Ch, class Tr, class Enum> inline std::basic_ostream<Ch, Tr>& operator <<(std::basic_ostream<Ch, Tr>& 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 <class Tr, class Enum> inline std::basic_ostream<char, Tr>& operator <<(std::basic_ostream<char, Tr>& os, const Enum& value) { return os << value._to_string(); } although it's better to handle at least wchar_t as well.