ostream_string.qbk 2.0 KB

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