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