Ticket #9299: 0001-Add-emplace_-back-front-to-circular_buffer.patch

File 0001-Add-emplace_-back-front-to-circular_buffer.patch, 4.5 KB (added by ai0867@…, 5 years ago)
  • include/boost/circular_buffer/base.hpp

    From 56f10e6104f407352ff1ab5e2743100bb7ece872 Mon Sep 17 00:00:00 2001
    From: Alexander van Gessel <ai0867@gmail.com>
    Date: Sat, 11 Nov 2017 00:14:51 +0100
    Subject: [PATCH 1/2] Add emplace_{back,front} to circular_buffer
    
    ---
     include/boost/circular_buffer/base.hpp | 80 ++++++++++++++++++++++++++++++++++
     1 file changed, 80 insertions(+)
    
    diff --git a/include/boost/circular_buffer/base.hpp b/include/boost/circular_buffer/base.hpp
    index 4babd9f..fa73e81 100644
    a b private:  
    14491449        BOOST_CATCH_END
    14501450    }
    14511451
     1452    template <class ...Args>
     1453    void emplace_back_impl(BOOST_FWD_REF(Args) ...args) {
     1454        if (full()) {
     1455            if (empty())
     1456                return;
     1457            replace(m_last, value_type(::boost::forward<Args>(args)...));
     1458            increment(m_last);
     1459            m_first = m_last;
     1460        } else {
     1461            boost::container::allocator_traits<Alloc>::construct(m_alloc, cb_details::to_address(m_last), ::boost::forward<Args>(args)...);
     1462            increment(m_last);
     1463            ++m_size;
     1464        }
     1465    }
     1466
     1467    template <class ...Args>
     1468    void emplace_front_impl(BOOST_FWD_REF(Args) ...args) {
     1469        BOOST_TRY {
     1470            if (full()) {
     1471                if (empty())
     1472                    return;
     1473                decrement(m_first);
     1474                replace(m_first, value_type(::boost::forward<Args>(args)...));
     1475                m_last = m_first;
     1476            } else {
     1477                decrement(m_first);
     1478                boost::container::allocator_traits<Alloc>::construct(m_alloc, cb_details::to_address(m_first), ::boost::forward<Args>(args)...);
     1479                ++m_size;
     1480            }
     1481        } BOOST_CATCH(...) {
     1482            increment(m_first);
     1483            BOOST_RETHROW
     1484        }
     1485        BOOST_CATCH_END
     1486    }
     1487
    14521488public:
    14531489    //! Insert a new element at the end of the <code>circular_buffer</code>.
    14541490    /*!
    public:  
    15781614        push_front(boost::move(temp));
    15791615    }
    15801616
     1617    //! Construct a new element at the end of the <code>circular_buffer</code>.
     1618    /*!
     1619        \post if <code>capacity() > 0</code> then <code>back() == item</code><br>
     1620              If the <code>circular_buffer</code> is full, the first element will be removed. If the capacity is
     1621              <code>0</code>, nothing will be inserted.
     1622        \param item The element to be inserted.
     1623        \throws Whatever <code>T::T(Args...)</code> throws.
     1624                Whatever <code>T::operator = (T&&)</code> throws.
     1625        \par Exception Safety
     1626             Basic; no-throw if the operation in the <i>Throws</i> section does not throw anything.
     1627        \par Iterator Invalidation
     1628             Does not invalidate any iterators with the exception of iterators pointing to the overwritten element.
     1629        \par Complexity
     1630             Constant (in the size of the <code>circular_buffer</code>).
     1631        \sa <code>\link push_back() push_back(const_reference)\endlink</code>,
     1632            <code>pop_back()</code>, <code>emplace_front()</code>
     1633    */
     1634    template <class ...Args>
     1635    void emplace_back(BOOST_FWD_REF(Args) ...args) {
     1636        emplace_back_impl(::boost::forward<Args>(args)...);
     1637    }
     1638
     1639    //! Construct a new element at the beginning of the <code>circular_buffer</code>.
     1640    /*!
     1641        \post if <code>capacity() > 0</code> then <code>back() == item</code><br>
     1642              If the <code>circular_buffer</code> is full, the last element will be removed. If the capacity is
     1643              <code>0</code>, nothing will be inserted.
     1644        \param item The element to be inserted.
     1645        \throws Whatever <code>T::T(Args...)</code> throws.
     1646                Whatever <code>T::operator = (T&&)</code> throws.
     1647        \par Exception Safety
     1648             Basic; no-throw if the operation in the <i>Throws</i> section does not throw anything.
     1649        \par Iterator Invalidation
     1650             Does not invalidate any iterators with the exception of iterators pointing to the overwritten element.
     1651        \par Complexity
     1652             Constant (in the size of the <code>circular_buffer</code>).
     1653        \sa <code>\link push_front() push_front(const_reference)\endlink</code>,
     1654            <code>pop_front()</code>, <code>emplace_back()</code>
     1655    */
     1656    template <class ...Args>
     1657    void emplace_front(BOOST_FWD_REF(Args) ...args) {
     1658        emplace_front_impl(::boost::forward<Args>(args)...);
     1659    }
     1660
    15811661    //! Remove the last element from the <code>circular_buffer</code>.
    15821662    /*!
    15831663        \pre <code>!empty()</code>