Boost logo

Boost Users :

From: Richard Howells (richard_at_[hidden])
Date: 2004-12-22 09:22:01


Well it might be crude but sometimes the pre-processor is your friend...

template<class T>
MyLogger & operator<<(MyLogger & log, T o)
{
#if defined(_DEBUG)
        // code goes here
#else
        // leave empty
#endif
}

...but your problem is still there because you don’t know what to put in
'code goes here'. I think you still need a family of strongly typed
MyLogger::print overloads to call there.

HTH

 - Richard

-----Original Message-----
From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Dan Dimerman
Sent: 22 December 2004 13:03
To: boost-users_at_[hidden]
Subject: [Boost-users] Re: Q: boost::format : can formatting
variablearguments lists be done ?

Richard Howells wrote:
> Vladimir is right.
>
> You've seen the problems and crashes that leaving type checking to the
> programmer causes. You need the compiler to do the checking for you.
>
> I suggest using the same kind of scheme as the iostreams library. You
might
/.../
> ...it will be (mostly) type safe - the type dangerous stuff is isolated to
> one place per output type - and you can extend it as you go. You'll
likely
> need extra formatting stuff and that's where boost::format may help you.
>

I was thinking about something like:

MyLogger::print( const boost::format& f )

and since all format's operator %() return a boost::format, I could with
this single function reap all the types handled by it at once.

I use a function rather than the operator << because they are actually
template functions, with the parameter being the severity.
So for _DEBUG versions, the MyLogger::print< DBG >() function
instantiates to a proper call to print, while in _RELEASE versions it
instantiates to an empty function. I just didn't see a clean way to do
this with operators.

Dan

_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users

-- 
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.296 / Virus Database: 265.6.3 - Release Date: 21/12/2004
 
-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.296 / Virus Database: 265.6.3 - Release Date: 21/12/2004
 

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net