2 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // Official repository: https://github.com/boostorg/beast
10 #ifndef BOOST_BEAST_WRITE_OSTREAM_HPP
11 #define BOOST_BEAST_WRITE_OSTREAM_HPP
13 #include <boost/beast/core/detail/config.hpp>
14 #include <boost/beast/core/type_traits.hpp>
15 #include <boost/beast/core/detail/ostream.hpp>
16 #include <type_traits>
23 /** Return an object representing a @b ConstBufferSequence.
25 This function wraps a reference to a buffer sequence and permits
26 the following operation:
28 @li `operator<<` to `std::ostream`. No character translation is
29 performed; unprintable and null characters will be transferred
30 as-is to the output stream.
36 std::cout << buffers(b.data()) << std::endl;
39 @param b An object meeting the requirements of @b ConstBufferSequence
40 to be streamed. The implementation will make a copy of this object.
41 Ownership of the underlying memory is not transferred, the application
42 is still responsible for managing its lifetime.
44 template<class ConstBufferSequence>
45 #if BOOST_BEAST_DOXYGEN
46 implementation_defined
48 detail::buffers_helper<ConstBufferSequence>
50 buffers(ConstBufferSequence const& b)
52 static_assert(boost::asio::is_const_buffer_sequence<
53 ConstBufferSequence>::value,
54 "ConstBufferSequence requirements not met");
55 return detail::buffers_helper<
56 ConstBufferSequence>{b};
59 /** Return an output stream that formats values into a @b DynamicBuffer.
61 This function wraps the caller provided @b DynamicBuffer into
62 a `std::ostream` derived class, to allow `operator<<` stream style
63 formatting operations.
67 ostream(buffer) << "Hello, world!" << std::endl;
70 @note Calling members of the underlying buffer before the output
71 stream is destroyed results in undefined behavior.
73 @param buffer An object meeting the requirements of @b DynamicBuffer
74 into which the formatted output will be placed.
76 @return An object derived from `std::ostream` which redirects output
77 The wrapped dynamic buffer is not modified, a copy is made instead.
78 Ownership of the underlying memory is not transferred, the application
79 is still responsible for managing its lifetime. The caller is
80 responsible for ensuring the dynamic buffer is not destroyed for the
81 lifetime of the output stream.
83 template<class DynamicBuffer>
84 #if BOOST_BEAST_DOXYGEN
85 implementation_defined
87 detail::ostream_helper<
88 DynamicBuffer, char, std::char_traits<char>,
89 detail::basic_streambuf_movable::value>
91 ostream(DynamicBuffer& buffer)
94 boost::asio::is_dynamic_buffer<DynamicBuffer>::value,
95 "DynamicBuffer requirements not met");
96 return detail::ostream_helper<
97 DynamicBuffer, char, std::char_traits<char>,
98 detail::basic_streambuf_movable::value>{buffer};