Construct buffer_prefix_view in-place

This commit is contained in:
Vinnie Falco
2017-07-06 21:17:57 -07:00
parent 8179019590
commit 8ee911f632
4 changed files with 39 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
Version 75: Version 75:
* Use file_body for valid requests, string_body otherwise. * Use file_body for valid requests, string_body otherwise.
* Construct buffer_prefix_view in-place
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View File

@@ -10,6 +10,7 @@
#include <beast/config.hpp> #include <beast/config.hpp>
#include <beast/core/type_traits.hpp> #include <beast/core/type_traits.hpp>
#include <beast/core/detail/in_place_init.hpp>
#include <boost/asio/buffer.hpp> #include <boost/asio/buffer.hpp>
#include <cstdint> #include <cstdint>
#include <type_traits> #include <type_traits>
@@ -78,12 +79,12 @@ public:
/// Copy assignment. /// Copy assignment.
buffer_prefix_view& operator=(buffer_prefix_view const&); buffer_prefix_view& operator=(buffer_prefix_view const&);
/** Construct a shortened buffer sequence. /** Construct a buffer sequence prefix.
@param n The maximum number of bytes in the wrapped @param n The maximum number of bytes in the prefix.
sequence. If this is larger than the size of passed, If this is larger than the size of passed, buffers,
buffers, the resulting sequence will represent the the resulting sequence will represent the entire
entire input sequence. input sequence.
@param buffers The buffer sequence to adapt. A copy of @param buffers The buffer sequence to adapt. A copy of
the sequence will be made, but ownership of the underlying the sequence will be made, but ownership of the underlying
@@ -91,6 +92,19 @@ public:
*/ */
buffer_prefix_view(std::size_t n, BufferSequence const& buffers); buffer_prefix_view(std::size_t n, BufferSequence const& buffers);
/** Construct a buffer sequence prefix in-place.
@param n The maximum number of bytes in the prefix.
If this is larger than the size of passed, buffers,
the resulting sequence will represent the entire
input sequence.
@param args Arguments forwarded to the contained buffers constructor.
*/
template<class... Args>
buffer_prefix_view(std::size_t n,
boost::in_place_init_t, Args&&... args);
/// Get a bidirectional iterator to the first element. /// Get a bidirectional iterator to the first element.
const_iterator const_iterator
begin() const; begin() const;

View File

@@ -9,6 +9,7 @@
#define BEAST_DETAIL_IN_PLACE_INIT_HPP #define BEAST_DETAIL_IN_PLACE_INIT_HPP
#include <boost/version.hpp> #include <boost/version.hpp>
#include <boost/optional/optional.hpp>
// Provide boost::in_place_init_t and boost::in_place_init // Provide boost::in_place_init_t and boost::in_place_init
// for Boost versions earlier than 1.63.0. // for Boost versions earlier than 1.63.0.

View File

@@ -157,7 +157,8 @@ setup(std::size_t n)
} }
template<class BufferSequence> template<class BufferSequence>
buffer_prefix_view<BufferSequence>::const_iterator:: buffer_prefix_view<BufferSequence>::
const_iterator::
const_iterator(const_iterator&& other) const_iterator(const_iterator&& other)
: b_(other.b_) : b_(other.b_)
, it_(std::move(other.it_)) , it_(std::move(other.it_))
@@ -165,7 +166,8 @@ const_iterator(const_iterator&& other)
} }
template<class BufferSequence> template<class BufferSequence>
buffer_prefix_view<BufferSequence>::const_iterator:: buffer_prefix_view<BufferSequence>::
const_iterator::
const_iterator(const_iterator const& other) const_iterator(const_iterator const& other)
: b_(other.b_) : b_(other.b_)
, it_(other.it_) , it_(other.it_)
@@ -174,7 +176,8 @@ const_iterator(const_iterator const& other)
template<class BufferSequence> template<class BufferSequence>
auto auto
buffer_prefix_view<BufferSequence>::const_iterator:: buffer_prefix_view<BufferSequence>::
const_iterator::
operator=(const_iterator&& other) -> operator=(const_iterator&& other) ->
const_iterator& const_iterator&
{ {
@@ -185,7 +188,8 @@ operator=(const_iterator&& other) ->
template<class BufferSequence> template<class BufferSequence>
auto auto
buffer_prefix_view<BufferSequence>::const_iterator:: buffer_prefix_view<BufferSequence>::
const_iterator::
operator=(const_iterator const& other) -> operator=(const_iterator const& other) ->
const_iterator& const_iterator&
{ {
@@ -256,6 +260,16 @@ buffer_prefix_view(std::size_t n, BufferSequence const& bs)
setup(n); setup(n);
} }
template<class BufferSequence>
template<class... Args>
buffer_prefix_view<BufferSequence>::
buffer_prefix_view(std::size_t n,
boost::in_place_init_t, Args&&... args)
: bs_(std::forward<Args>(args)...)
{
setup(n);
}
template<class BufferSequence> template<class BufferSequence>
inline inline
auto auto