]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/beast/core/buffers_to_string.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / beast / core / buffers_to_string.hpp
1 //
2 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
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)
6 //
7 // Official repository: https://github.com/boostorg/beast
8 //
9
10 #ifndef BOOST_BEAST_BUFFERS_TO_STRING_HPP
11 #define BOOST_BEAST_BUFFERS_TO_STRING_HPP
12
13 #include <boost/beast/core/detail/config.hpp>
14 #include <boost/beast/core/detail/type_traits.hpp>
15 #include <boost/asio/buffer.hpp>
16 #include <string>
17
18 namespace boost {
19 namespace beast {
20
21 /** Return a string representing the contents of a buffer sequence.
22
23 This function returns a string representing an entire buffer
24 sequence. Nulls and unprintable characters in the buffer
25 sequence are inserted to the resulting string as-is. No
26 character conversions are performed.
27
28 @param buffers The buffer sequence to convert
29
30 @par Example
31
32 This function writes a buffer sequence converted to a string
33 to `std::cout`.
34
35 @code
36 template<class ConstBufferSequence>
37 void print(ConstBufferSequence const& buffers)
38 {
39 std::cout << buffers_to_string(buffers) << std::endl;
40 }
41 @endcode
42 */
43 template<class ConstBufferSequence>
44 std::string
45 buffers_to_string(ConstBufferSequence const& buffers)
46 {
47 std::string result;
48 result.reserve(boost::asio::buffer_size(buffers));
49 for(boost::asio::const_buffer buffer :
50 detail::buffers_range(buffers))
51 result.append(reinterpret_cast<
52 char const*>(buffer.data()), buffer.size());
53 return result;
54 }
55
56 } // beast
57 } // boost
58
59 #endif