|
Boost : |
From: Jeff Garland (jeff_at_[hidden])
Date: 2002-04-09 11:38:56
Ernie Makris wrote:
> One way I've been toying with zero impact, is the following:
>
> template <bool cond>
> struct DebugSys {
> enum { R = 0 };
> };
>
> template <>
> struct DebugSys<true> {
> enum { R = 1 };
> };
>
> if( DebugSys<DBUGFLAG>::R )
> logger << log_debug << "Starting server....";
>
> most, if not all compilers remove the unreachable code when R evaluates to
> 0, when DBUGFLAG = false. It's a little bit ugly, but it forgoes macros, and
> your program has a single source source set. Rather than two versions of the
> set. It makes debugging easier. The compiler decides when to remove the code
> altogether.
This is the same result as null ostream, different interface. I personally prefer the zero client
code impact of null stream.
> One of the drawbacks to this technique is, you cannot switch , dynamically,
> logging on and off when log statements are written this way. The code no
> longer exists.
Right, neither of these apply if you want dynamically switchable tracing capabilities...
Jeff
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk