Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2004-11-13 05:27:55


Eljay Love-Jensen wrote:
> Hi Reece,
>
> You'd have to run the source code through the pre-processor twice to remove
> the comments.
>
> Comments are stripped out first, then macro-expansion. (Not surprisingly,
> Microsoft's compiler is non-compliant, and the trick works on their
> platform.)

How about:

class null_log
{
    public:
       template< typename T >
       null_log & operator<<( const T & )
       {
          return *this;
       }
};

null_log log;

#define BOOST_LOG(id) log

This should work and a good compiler should be able to optimize away the
log output, leaving only the small footprint of the global variable. It
also has the advantage of being multi-line compatible:

BOOST_LOG(dbg) << "message: "
    << foobar;

Regards,
Reece


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk