reverse
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.
<boost/iostreams/reverse.hpp>
namespace boost { namespace iostreams { template<typename Filter> implementation-defined reverse(const Filter& filter); } } // End namespace boost::io
#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); ... }
Revised 20 May, 2004
© Copyright Jonathan Turkanis, 2004
Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)