Function Template put

Overview
Example
Headers
Reference

Overview

The function template put provides a uniform interface for writing a character to a Sink, for use in the definitions of new Filter types (see Example).

Example

The following code illustrates the use of the function put in the definition of an OutputFilter.

    #include <ctype.h>                        // toupper
    #include <boost/iostreams/concepts.hpp>   // output_filter 
    #include <boost/iostreams/operations.hpp> // put

    using namespace std;
    namespace io = boost::iostreams;

    struct toupper_filter : public io::output_filter {
        template<typename Sink>
        bool put(Sink& snk, char c)
        {
            return io::put(snk, toupper((unsigned char) c));
        }
    };

Headers

<boost/iostreams/operations.hpp>
<boost/iostreams/put.hpp>

Reference

Description

Attempts to write a character to a given instance of the template parameter Sink, returning true for success.

Synopsis

namespace boost { namespace iostreams {
              
    template<typename Sink>     
    void put(Sink& snk, typename char_type_of<Sink>::type c);

} } // End namespace boost::io

Template Parameters

Sink- A indirect model of Sink or a standard output stream or stream buffer type.

Function Parameters

snk- An instance of Sink

Semantics

    template<typename Sink>     
    void put(Sink& snk, typename char_type_of<Sink>::type c);

The semantics of put depends on the category of Sink as follows:

category_of<Sink>::typesemantics
convertible to direct_tag compile-time error
convertible to ostream_tag invokes snk.put(c)
convertible to streambuf_tag but not to ostream_tag invokes snk.sputc(c)
otherwise invokes snk.write(&c, 1)