Skip to content

Commit 3e0c33f

Browse files
committed
Add emplace_{back,front} to circular_buffer_space_optimized
1 parent 0f2cc10 commit 3e0c33f

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

include/boost/circular_buffer/space_optimized.hpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,62 @@ public:<br>
905905
circular_buffer<T, Alloc>::push_front();
906906
}
907907

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

0 commit comments

Comments
 (0)