The code below is compiled successfully with both GCC and MSVC:
#include <iostream>
#include <sstream>
template <class C>
class basic_format
{
public:
template <typename T>
basic_format & operator << (const T & val)
{
out << val;
return *this;
}
std::basic_string<C> str() const { return out.str(); }
operator std::basic_string<C>() const { return str(); }
private:
std::basic_ostringstream<C> out;
};