Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-08-24 11:59:59


"Jonathan Turkanis" <technews_at_[hidden]> wrote in message
news:cgem4t$r20$1_at_sea.gmane.org...
>
> "Pavel Vozenilek" <pavel_vozenilek_at_[hidden]> wrote in message:

> > - 'tee' like output stream, they take data and re-send
> > them all into two other streams

> struct tee : boost::io::output_filter {
> tee(std::ostream& dest) : dest(dest) { }
>
> template<typename Sink>
> void write(Sink& snk, char* s, std::streamsize n)
> {
> // Write to the downstream Sink
> boost::io::write(snk, s, n);
>
> // Write to the stored ostream:
> dest.write(s, n);
> }
>
> std::ostream& dest;
> };

Better:

    struct tee : boost::io::sink {
        tee(std::ostream& first, std::ostream& second)
            : first(first), second(second)
            { }
        void write(const char* s, std::streamsize n)
        {
            first.write(s, n);
            second.write(s, n);
        }
        std::ostream& first;
        std::ostream& second;
    };

    std::ostream first;
    std::ostream second;
    boost::io::stream_facade<tee> out(tee(first, second));
    out << "This is simpler and more efficient\n";

Jonathan


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