diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d90144d..a6694f4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ Version 75: * Use file_body for valid requests, string_body otherwise. +* Construct buffer_prefix_view in-place -------------------------------------------------------------------------------- diff --git a/include/beast/core/buffer_prefix.hpp b/include/beast/core/buffer_prefix.hpp index a5417b62..6625b67e 100644 --- a/include/beast/core/buffer_prefix.hpp +++ b/include/beast/core/buffer_prefix.hpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -78,12 +79,12 @@ public: /// Copy assignment. 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 - sequence. If this is larger than the size of passed, - buffers, the resulting sequence will represent the - entire input sequence. + @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 buffers The buffer sequence to adapt. A copy of 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); + /** 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 + buffer_prefix_view(std::size_t n, + boost::in_place_init_t, Args&&... args); + /// Get a bidirectional iterator to the first element. const_iterator begin() const; diff --git a/include/beast/core/detail/in_place_init.hpp b/include/beast/core/detail/in_place_init.hpp index f97ad085..2a0ab615 100644 --- a/include/beast/core/detail/in_place_init.hpp +++ b/include/beast/core/detail/in_place_init.hpp @@ -9,6 +9,7 @@ #define BEAST_DETAIL_IN_PLACE_INIT_HPP #include +#include // Provide boost::in_place_init_t and boost::in_place_init // for Boost versions earlier than 1.63.0. diff --git a/include/beast/core/impl/buffer_prefix.ipp b/include/beast/core/impl/buffer_prefix.ipp index ff5afda8..f6c6470e 100644 --- a/include/beast/core/impl/buffer_prefix.ipp +++ b/include/beast/core/impl/buffer_prefix.ipp @@ -157,7 +157,8 @@ setup(std::size_t n) } template -buffer_prefix_view::const_iterator:: +buffer_prefix_view:: +const_iterator:: const_iterator(const_iterator&& other) : b_(other.b_) , it_(std::move(other.it_)) @@ -165,7 +166,8 @@ const_iterator(const_iterator&& other) } template -buffer_prefix_view::const_iterator:: +buffer_prefix_view:: +const_iterator:: const_iterator(const_iterator const& other) : b_(other.b_) , it_(other.it_) @@ -174,7 +176,8 @@ const_iterator(const_iterator const& other) template auto -buffer_prefix_view::const_iterator:: +buffer_prefix_view:: +const_iterator:: operator=(const_iterator&& other) -> const_iterator& { @@ -185,7 +188,8 @@ operator=(const_iterator&& other) -> template auto -buffer_prefix_view::const_iterator:: +buffer_prefix_view:: +const_iterator:: operator=(const_iterator const& other) -> const_iterator& { @@ -256,6 +260,16 @@ buffer_prefix_view(std::size_t n, BufferSequence const& bs) setup(n); } +template +template +buffer_prefix_view:: +buffer_prefix_view(std::size_t n, + boost::in_place_init_t, Args&&... args) + : bs_(std::forward(args)...) +{ + setup(n); +} + template inline auto