1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN">
4 <TITLE>Function Template put
</TITLE>
5 <LINK REL=
"stylesheet" HREF=
"../../../../boost.css">
6 <LINK REL=
"stylesheet" HREF=
"../theme/iostreams.css">
12 <H1 CLASS=
"title">Function Template
<CODE>put
</CODE></H1>
17 <DL class=
"page-index">
18 <DT><A href=
"#overview">Overview
</A></DT>
19 <DT><A href=
"#example">Example
</A></DT>
20 <DT><A href=
"#headers">Headers
</A></DT>
21 <DT><A href=
"#reference">Reference
</A></DT>
24 <A NAME=
"overview"></A>
28 The function template
<CODE>put
</CODE> provides a uniform interface for writing a character to a
<A HREF=
"../concepts/sink.html">Sink
</A>, for use in the definitions of new
<A HREF=
"../guide/concepts.html#filter_concepts">Filter
</A> types (
<I>see
</I> <A HREF=
"#example">Example
</A>).
31 <A NAME=
"example"></A>
35 The following code illustrates the use of the function
<CODE>put
</CODE> in the definition of an
<A HREF=
"../concepts/output_filter.html">OutputFilter
</A>.
38 <PRE CLASS=
"broken_ie"> <SPAN CLASS=
"preprocessor">#include
</SPAN> <SPAN CLASS=
"literal"><ctype.h
></SPAN> <SPAN CLASS=
"comment">// toupper
</SPAN>
39 <SPAN CLASS=
"preprocessor">#include
</SPAN> <A CLASS=
"header" HREF=
"../../../../boost/iostreams/concepts.hpp"><SPAN CLASS=
"literal"><boost/iostreams/concepts.hpp
></SPAN></A> <SPAN CLASS=
"comment">// output_filter
</SPAN>
40 <SPAN CLASS=
"preprocessor">#include
</SPAN> <A CLASS=
"header" HREF=
"../../../../boost/iostreams/operations.hpp"><SPAN CLASS=
"literal"><boost/iostreams/operations.hpp
></SPAN></A> <SPAN CLASS=
"comment">// put
</SPAN>
42 <SPAN CLASS=
"keyword">using
</SPAN> <SPAN CLASS=
"keyword">namespace
</SPAN> std;
43 <SPAN CLASS=
"keyword">namespace
</SPAN> io = boost::iostreams;
45 <SPAN CLASS=
"keyword">struct
</SPAN> toupper_filter :
<SPAN CLASS=
"keyword">public
</SPAN> io::output_filter {
46 <SPAN CLASS=
"keyword">template
</SPAN><<SPAN CLASS=
"keyword">typename
</SPAN> Sink
>
47 <SPAN CLASS=
"keyword">bool
</SPAN> put(Sink
& snk,
<SPAN CLASS=
"keyword">char
</SPAN> c)
49 <SPAN CLASS=
"keyword">return
</SPAN> io::put(snk, toupper((
<SPAN CLASS=
"keyword">unsigned
</SPAN> <SPAN CLASS=
"keyword">char
</SPAN>) c));
53 <A NAME=
"headers"></A>
57 <DT><A CLASS=
"header" HREF=
"../../../../boost/iostreams/operations.hpp"><CODE><boost/iostreams/operations.hpp
></CODE></A></DT>
58 <DT><A CLASS=
"header" HREF=
"../../../../boost/iostreams/put.hpp"><CODE><boost/iostreams/put.hpp
></CODE></A></DT>
61 <A NAME=
"reference"></A>
64 <A NAME=
"description"></A>
67 <P>Attempts to write a character to a given instance of the template parameter
<CODE>Sink
</CODE>, returning
<CODE>true
</CODE> for success.
</P>
69 <A NAME=
"synopsis"></A>
72 <PRE CLASS=
"broken_ie"><SPAN CLASS=
"keyword">namespace
</SPAN> boost {
<SPAN CLASS=
"keyword">namespace
</SPAN> iostreams {
74 <SPAN CLASS=
"keyword">template
</SPAN><<SPAN CLASS=
"keyword">typename
</SPAN> <A CLASS=
"documented" HREF=
"#template_params">Sink
</A>>
75 <SPAN CLASS=
"keyword">void
</SPAN> put(Sink
& <A CLASS=
"documented" HREF=
"#function_params">snk
</A>,
<SPAN CLASS=
"keyword">typename
</SPAN> <A CLASS=
"documented" HREF=
"../guide/traits.html#char_type_of_ref">char_type_of
</A><Sink
>::type c);
77 } }
<SPAN CLASS=
"comment">// End namespace boost::io
</SPAN></PRE>
79 <A NAME=
"template_params"></A>
80 <H4>Template Parameters
</H4>
82 <TABLE STYLE=
"margin-left:2em" BORDER=
0 CELLPADDING=
2>
85 <TD VALIGN=
"top"><I>Sink
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
86 <TD>A
<A HREF=
"../concepts/direct.html">indirect
</A> model of
<A HREF=
"../concepts/sink.html">Sink
</A> or a standard output stream or stream buffer type.
90 <A NAME=
"function_params"></A>
91 <H4>Function Parameters
</H4>
93 <TABLE STYLE=
"margin-left:2em" BORDER=
0 CELLPADDING=
2>
96 <TD VALIGN=
"top"><I>snk
</I></TD><TD WIDTH=
"2em" VALIGN=
"top">-
</TD>
97 <TD>An instance of
<CODE>Sink
</CODE></TD>
101 <A NAME=
"semantics"></A>
104 <PRE CLASS=
"broken_ie"> <SPAN CLASS=
"keyword">template
</SPAN><<SPAN CLASS=
"keyword">typename
</SPAN> Sink
>
105 <SPAN CLASS=
"keyword">void
</SPAN> put(Sink
& snk,
<SPAN CLASS=
"keyword">typename
</SPAN> char_type_of
<Sink
>::type c);
</PRE>
107 <P>The semantics of
<CODE>put
</CODE> depends on the
<A HREF=
"../guide/traits.html#category">category
</A> of
<CODE>Sink
</CODE> as follows:
</P>
109 <TABLE STYLE=
"margin:0,0,2em,2em" BORDER=
1 CELLPADDING=
4>
110 <TR><TH><CODE>category_of
<Sink
>::type
</CODE></TH><TH>semantics
</TH></TR>
112 <TD VALIGN=
"top">convertible to
<A HREF=
"../guide/traits.html#category_tags"><CODE>direct_tag
</CODE></A></TD>
113 <TD>compile-time error
</CODE></TD>
116 <TD VALIGN=
"top">convertible to
<A HREF=
"../guide/traits.html#category_tags"><CODE>ostream_tag
</CODE></A></TD>
117 <TD>invokes
<CODE>snk.put(c)
</CODE></TD>
120 <TD VALIGN=
"top">convertible to
<A HREF=
"../guide/traits.html#category_tags"><CODE>streambuf_tag
</CODE></A> but not to
<A HREF=
"../guide/traits.html#category_tags"><CODE>ostream_tag
</CODE></A></TD>
121 <TD>invokes
<CODE>snk.sputc(c)
</CODE></TD>
124 <TD VALIGN=
"top">otherwise
</TD>
125 <TD>invokes
<CODE>snk.write(
&c,
1)
</CODE></TD>
129 <!-- Begin Footer -->
133 <P CLASS=
"copyright">© Copyright
2008 <a href=
"http://www.coderage.com/" target=
"_top">CodeRage, LLC
</a><br/>© Copyright
2004-
2007 <a href=
"http://www.coderage.com/turkanis/" target=
"_top">Jonathan Turkanis
</a></P>
134 <P CLASS=
"copyright">
135 Distributed under the Boost Software License, Version
1.0. (See accompanying file LICENSE_1_0.txt or copy at
<A HREF=
"http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt
</A>)