2 // Copyright (c) 2013-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)
8 #ifndef BEAST_TO_STRING_HPP
9 #define BEAST_TO_STRING_HPP
11 #include <beast/config.hpp>
12 #include <beast/core/buffer_concepts.hpp>
13 #include <boost/asio/buffer.hpp>
18 /** Convert a @b `ConstBufferSequence` to a `std::string`.
20 This function will convert the octets in a buffer sequence to a string.
21 All octets will be inserted into the resulting string, including null
22 or unprintable characters.
24 @param buffers The buffer sequence to convert.
26 @return A string representing the contents of the input area.
28 @note This function participates in overload resolution only if
29 the buffers parameter meets the requirements of @b `ConstBufferSequence`.
31 template<class ConstBufferSequence>
35 typename std::enable_if<
36 is_ConstBufferSequence<ConstBufferSequence>::value,
39 to_string(ConstBufferSequence const& buffers)
41 using boost::asio::buffer_cast;
42 using boost::asio::buffer_size;
44 s.reserve(buffer_size(buffers));
45 for(auto const& buffer : buffers)
46 s.append(buffer_cast<char const*>(buffer),