From 21cbca4d560c64fc80a608af60545bd89f84dca5 Mon Sep 17 00:00:00 2001 From: Alexander van Gessel Date: Sat, 11 Nov 2017 00:15:08 +0100 Subject: [PATCH 2/2] Add emplace_{back,front} to circular_buffer_space_optimized --- include/boost/circular_buffer/space_optimized.hpp | 54 +++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/include/boost/circular_buffer/space_optimized.hpp b/include/boost/circular_buffer/space_optimized.hpp index 3d00173..4821729 100644 --- a/include/boost/circular_buffer/space_optimized.hpp +++ b/include/boost/circular_buffer/space_optimized.hpp @@ -905,6 +905,60 @@ public: circular_buffer::push_front(); } + //! Construct a new element at the end of the space optimized circular buffer. + /*! + \post if capacity().%capacity() > 0 then back() == item
+ If the circular_buffer_space_optimized is full, the first element will be removed. If the + capacity is 0, nothing will be inserted.

+ The amount of allocated memory in the internal buffer may be predictively increased. + \param item The element to be inserted. + \throws "An allocation error" if memory is exhausted (std::bad_alloc if the standard allocator is + used). + Whatever T::T(Args...) throws. + Whatever T::operator = (T&&) throws. + \par Exception Safety + Basic. + \par Iterator Invalidation + Invalidates all iterators pointing to the circular_buffer_space_optimized (except iterators + equal to end()). + \par Complexity + Linear (in the size of the circular_buffer_space_optimized). + \sa \link push_front() push_front(const_reference)\endlink, pop_back(), + pop_front() + */ + template + void emplace_back(BOOST_FWD_REF(Args) ...args) { + check_low_capacity(); + circular_buffer::emplace_back(::boost::forward(args)...); + } + + //! Construct a new element at the beginning of the space optimized circular buffer. + /*! + \post if capacity().%capacity() > 0 then front() == item
+ If the circular_buffer_space_optimized is full, the last element will be removed. If the + capacity is 0, nothing will be inserted.

+ The amount of allocated memory in the internal buffer may be predictively increased. + \param item The element to be inserted. + \throws "An allocation error" if memory is exhausted (std::bad_alloc if the standard allocator is + used). + Whatever T::T(Args...) throws or nothing if T::T(T&&) is noexcept. + Whatever T::operator = (T&&) throws. + \par Exception Safety + Basic. + \par Iterator Invalidation + Invalidates all iterators pointing to the circular_buffer_space_optimized (except iterators + equal to end()). + \par Complexity + Linear (in the size of the circular_buffer_space_optimized). + \sa \link push_back() push_back(const_reference)\endlink, pop_back(), + pop_front() + */ + template + void emplace_front(BOOST_FWD_REF(Args) ...args) { + check_low_capacity(); + circular_buffer::emplace_front(::boost::forward(args)...); + } + //! Remove the last element from the space optimized circular buffer. /*! \pre !empty() -- 2.11.0