On Fri, Dec 08, 2006 at 12:56:29PM +0000, Sandro Santilli wrote:

Few more comments on this.

> Log message:
>               * libbase/log.{cpp,h}: add a templated operator << for
>                 printing *any* class that has an output operator defined.
>                 It could replace most operator<< methods, but I won't go
>                 there for now... just happy with derived Range2d printing 
> facility.

> -LogFile::operator << (std::string &s)
> +LogFile::operator << (const std::string &s)

This is needed because stringstream.str() returns a 'const' string,
so if we have NO method that takes a 'const' string the templated
method (const reference to *any* class) is choosed again, resulting
in an infinite recursion.

> +#include <sstream>

Unfortunately the "templated" implementation  requires to have
this include in the log.h header...

> +
> +    /// Print anything that can be printed on a stringstream
> +    //
> +    /// This template function could replace ALL but
> +    /// operator << (const std::string&) members of
> +    /// LogFile class.
> +    ///
> +    template <class T>
> +    LogFile& operator << (const T& any)
> +    {
> +         std::stringstream ss;
> +         ss << any;
> +         return *this << ss.str();
> +    }

As you can see we could drop *all* operator<< and just
leave the one for std::string. The downside is we'll be
using stringstream for printing *everything*, but the
code would be much more cleaner..

--strk;


_______________________________________________
Gnash-commit mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/gnash-commit

Reply via email to