• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1[/
2Copyright 2019 Glen Joseph Fernandes
3(glenjofe@gmail.com)
4
5Distributed under the Boost Software License, Version 1.0.
6(http://www.boost.org/LICENSE_1_0.txt)
7]
8
9[article ostream_string
10[quickbook 1.5]
11[authors [Fernandes, Glen]]
12[copyright 2019 Glen Joseph Fernandes]
13[license Distributed under the Boost Software License, Version 1.0.]]
14
15[section Overview]
16
17The header <boost/utility/ostream_string.hpp> provides the function template
18`boost::ostream_string` for formatted output that satisfies the requirements of
19\[ostream.formatted.reqmts\].
20
21[endsect]
22
23[section Examples]
24
25The inserter for class template `basic_string_view` could be implemented as
26follows:
27
28```
29template<class charT, class traits>
30std::basic_ostream<charT, traits>&
31operator<<(std::basic_ostream<charT, traits>& os,
32    const basic_string_view<charT, traits>& str)
33{
34    return boost::ostream_string(os, str.data(), str.size());
35}
36```
37
38[endsect]
39
40[section Reference]
41
42```
43namespace boost {
44
45template<class charT, class traits>
46std::basic_ostream<charT, traits>&
47ostream_string(std::basic_ostream<charT, traits>& os,
48    const charT* data, std::size_t size);
49
50} /* boost */
51```
52
53[heading Free functions]
54
55[variablelist
56[[`template<class charT, class traits> std::basic_ostream<charT, traits>&
57ostream_string(std::basic_ostream<charT, traits>& os, const charT* data,
58std::size_t size);`]
59[[variablelist
60[[Effects]
61[Behaves like a formatted inserter (as described in
62\[ostream.formatted.reqmts\]) of `os`. Creates a character sequence `seq` of
63`size` characters starting at `data`, each widened using `os.widen()`
64(\[basic.ios.members\]). Determines padding for `seq` as described in
65\[ostream.formatted.reqmts\]. Inserts `seq` into `os`. Calls `width(0)`.]]
66[[Returns][`os`.]]]]]]
67
68[endsect]
69
70[section History]
71
72[heading boost 1.71]
73
74* Glen Fernandes updated the implementation of the `basic_string_ref` and
75`basic_string_view` stream insertion operators to write directly to the
76`basic_streambuf` and refactored that functionality into this common utility.
77
78[endsect]
79