Function Template reverse

Description
Headers
Synopsis
Example

Description

The function template reverse takes a Filter and returns a new Filter which performs the same filtering operation as the original Filter but which is an OutputFilter if the orginal Filter was an InputFilter and and InputFilter if the orginal Filter was an OutputFilter. Roughly speaking, it reverses the direction of a given Filter.

The implementation of reverse makes use of the class template one_step_filter, which filters an entire sequence of data at once. Therefore, a Filter returned by reverse may have higher memory use than the original Filter and is unsuitable for use with streams of data which have no definite endpoint.

Headers

<boost/iostreams/reverse.hpp>

Synopsis

namespace boost { namespace iostreams {
                    
template<typename Filter>
implementation-defined reverse(const Filter& filter);

} } // End namespace boost::io

Example

The following example defines an
OutputFilter and uses it to filter standard input.
#include <cctype>                        // toupper
#include <iostream>
#include <boost/iostreams/concepts.hpp>         // output_filter
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/reverse.hpp>

using namespace std;
using namespace boost::io;

// Converts characters to uppercase
struct toupper_filter : output_filter {
    void put(char c, std::streambuf& dest)
    {
        dest.sputc(toupper(c));
    }
};

int main()
{
    filtering_stream<input> in;
    in.push(reverse(toupper_filter()));
    in.push(cin);
    ...
}