Boost logo

Boost :

From: Dave Abrahams (abrahams_at_[hidden])
Date: 2000-03-07 23:07:26


on 3/7/00 7:59 AM, Moore, Paul at Paul.Moore_at_[hidden] wrote:

> Ugh. That's a real issue. I hadn't thought of that problem, but I guess you
> are right. Sounds like it should be rejected.
>
> OK, does anybody have any other suggestions? I'm looking for a
> debugging-printf type of statement, so it needs to be pretty minimal, but I
> want to avoid
> 1. Creating permanent stream objects
> (needs me to think of names, or use {}).
> 2. Multiline incantations for one-line messages.
> 3. Risk of partial messages being output (flush issue).

If you don't want to derive from std::ostringstream, just contain one and
write a template operator<<

// crude implementation
struct MyClass {
    ~MyClass() { ::MessageBox(s.c_str()); }
    mutable std::ostringstream s;
};

template <class T>
std::ostream& operator<<(const MyClass& s, const T& x)
{
    return s.s << x;
}

All your existing code should still work.
-Dave


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