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#ifndef BOOST_IO_OSTREAM_PUT_HPP
9#define BOOST_IO_OSTREAM_PUT_HPP
10
11#include <boost/io/detail/buffer_fill.hpp>
12#include <boost/io/detail/ostream_guard.hpp>
13
14namespace boost {
15namespace io {
16
17template<class charT, class traits>
18inline std::basic_ostream<charT, traits>&
19ostream_put(std::basic_ostream<charT, traits>& os, const charT* data,
20 std::size_t size)
21{
22 typedef std::basic_ostream<charT, traits> stream;
23 detail::ostream_guard<charT, traits> guard(os);
24 typename stream::sentry entry(os);
25 if (entry) {
26 std::basic_streambuf<charT, traits>& buf = *os.rdbuf();
27 std::size_t width = static_cast<std::size_t>(os.width());
28 if (width <= size) {
29 if (static_cast<std::size_t>(buf.sputn(data, size)) != size) {
30 return os;
31 }
32 } else if ((os.flags() & stream::adjustfield) == stream::left) {
33 if (static_cast<std::size_t>(buf.sputn(data, size)) != size ||
34 !detail::buffer_fill(buf, os.fill(), width - size)) {
35 return os;
36 }
37 } else if (!detail::buffer_fill(buf, os.fill(), width - size) ||
38 static_cast<std::size_t>(buf.sputn(data, size)) != size) {
39 return os;
40 }
41 os.width(0);
42 }
43 guard.release();
44 return os;
45}
46
47} /* io */
48} /* boost */
49
50#endif
51

source code of boost/libs/io/include/boost/io/ostream_put.hpp