Ticket #9299: 0002-Add-emplace_-back-front-to-circular_buffer_space_opt.patch

File 0002-Add-emplace_-back-front-to-circular_buffer_space_opt.patch, 3.9 KB (added by ai0867@…, 5 years ago)
  • include/boost/circular_buffer/space_optimized.hpp

    From 21cbca4d560c64fc80a608af60545bd89f84dca5 Mon Sep 17 00:00:00 2001
    From: Alexander van Gessel <ai0867@gmail.com>
    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 b public:  
    905905        circular_buffer<T, Alloc>::push_front();
    906906    }
    907907
     908    //! Construct a new element at the end of the space optimized circular buffer.
     909    /*!
     910        \post if <code>capacity().%capacity() > 0</code> then <code>back() == item</code><br>
     911              If the <code>circular_buffer_space_optimized</code> is full, the first element will be removed. If the
     912              capacity is <code>0</code>, nothing will be inserted.<br><br>
     913              The amount of allocated memory in the internal buffer may be predictively increased.
     914        \param item The element to be inserted.
     915        \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
     916                used).
     917                Whatever <code>T::T(Args...)</code> throws.
     918                Whatever <code>T::operator = (T&&)</code> throws.
     919        \par Exception Safety
     920             Basic.
     921        \par Iterator Invalidation
     922             Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
     923             equal to <code>end()</code>).
     924        \par Complexity
     925             Linear (in the size of the <code>circular_buffer_space_optimized</code>).
     926        \sa <code>\link push_front() push_front(const_reference)\endlink</code>, <code>pop_back()</code>,
     927            <code>pop_front()</code>
     928    */
     929    template <class ...Args>
     930    void emplace_back(BOOST_FWD_REF(Args) ...args) {
     931        check_low_capacity();
     932        circular_buffer<T, Alloc>::emplace_back(::boost::forward<Args>(args)...);
     933    }
     934
     935    //! Construct a new element at the beginning of the space optimized circular buffer.
     936    /*!
     937        \post if <code>capacity().%capacity() > 0</code> then <code>front() == item</code><br>
     938              If the <code>circular_buffer_space_optimized</code> is full, the last element will be removed. If the
     939              capacity is <code>0</code>, nothing will be inserted.<br><br>
     940              The amount of allocated memory in the internal buffer may be predictively increased.
     941        \param item The element to be inserted.
     942        \throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
     943                used).
     944                Whatever <code>T::T(Args...)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept.
     945                Whatever <code>T::operator = (T&&)</code> throws.
     946        \par Exception Safety
     947             Basic.
     948        \par Iterator Invalidation
     949             Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
     950             equal to <code>end()</code>).
     951        \par Complexity
     952             Linear (in the size of the <code>circular_buffer_space_optimized</code>).
     953        \sa <code>\link push_back() push_back(const_reference)\endlink</code>, <code>pop_back()</code>,
     954            <code>pop_front()</code>
     955    */
     956    template <class ...Args>
     957    void emplace_front(BOOST_FWD_REF(Args) ...args) {
     958        check_low_capacity();
     959        circular_buffer<T, Alloc>::emplace_front(::boost::forward<Args>(args)...);
     960    }
     961
    908962    //! Remove the last element from the space optimized circular buffer.
    909963    /*!
    910964        \pre <code>!empty()</code>