
It's needed copy contructor for temporaries:
Right on :D Thanks for pointing it out. I used it in a different manner before, and there was no need for it.
Second, gcc doesn't accept "log" for namespace name.
Got it. Here's the new version: #include <iosfwd> #include <sstream> namespace boost { namespace logtl /* note: gcc does not allow 'log' as a namespace */{ // allow finding the prototype for a log function template<class char_type, class traits = ::std::char_traits<char_type>, class aloc = ::std::allocator<char_type> > struct log_func { typedef void (*type)(const std::basic_string<char_type,traits,aloc> &); }; // allow writing to a log template<class char_type, class traits = ::std::char_traits<char_type>, class aloc = ::std::allocator<char_type> > struct basic_logstream { private: typedef typename log_func<char_type,traits,aloc>::type log_func_type; typedef ::std::basic_ostringstream<char_type,traits,aloc> ostring_stream_type; typedef ::std::basic_ostream<char_type,traits> ostream_type; public: explicit basic_logstream( log_func_type func) : m_func(func) {} basic_logstream( const basic_logstream & other) : m_func(other.m_func) { m_buffer << other.m_buffer.str(); other.m_func = 0; } ~basic_logstream() { if ( m_func) m_func( m_buffer.str() ); } template< class T> basic_logstream & operator<<( const T & val) { m_buffer << val; return *this; } typedef std::ostream & (*ostream_func)(std::ostream & ); basic_logstream & operator<<( ostream_func f) { f( m_buffer); return *this; } // in case the underlying stream is needed... ostream_type & ostream() { return m_buffer; } private: ostring_stream_type m_buffer; mutable log_func_type m_func; }; typedef basic_logstream<char> logstream; typedef basic_logstream<wchar_t> wlogstream; }} Best, John