Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-08-24 12:31:10


"Darren Cook" <darren_at_[hidden]> wrote in message
news:412AECFB.8060609_at_dcook.org...
> > Download:
> > http://groups.yahoo.com/group/boost/files/more_io_4.zip [or]
> > http://boost-sandbox.sourceforge.net/more_io_4.zip
>
> Are the docs available online anywhere?
>
> > * added generalizations to the new-line and skip-line manipulators
>
> I won't get time to look at, let alone review, this and the other
upcoming
> IO libraries, but I wondered if any of them (or perhaps even std
> components??) allow me to easily solve this problem:

<snip>

> 'brd' is an object representing a game board and it outputs the
values in a
> 2d array. The operator<< does not output a leading carriage-return,
but
> smart assert outputs something like this:
>
> brd = ' 1 2 3 4 5 6
> 7 8 9 a b c
> d e f g h i
> ';
>
> So, what I want is something to say insert a carriage-return before
calling
> operator<<, e.g.
> SMART_ASSERT( this==that )(prefix_cr(brd))(this)(that);

Why not something like:

    template<typename T>
    struct cr_prefixed {
        cr_prefixed(T& t) : t(t) { }
        void print(std::ostream& out) const
        {
            out << "\n" << t;
        }
        T& t;
    };

    template<typename T>
    std::ostream& operator<<(std::ostream& out, const cr_prefixed<T>&
p)
    {
        p.print(out);
        return out;
    }

    template<typename T>
    cr_prefixed<T> prefix_cr(T& t) { return cr_prefixed<T>(t); }

Is there a more general version of the problem?

Jonathan


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