Skip to content

Commit f97bcf6

Browse files
committed
Add emplace_{back,front} to circular_buffer_space_optimized
1 parent 85a4c6d commit f97bcf6

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

include/boost/circular_buffer/space_optimized.hpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,76 @@ public:<br>
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+
#ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES
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+
#else
936+
template <class V>
937+
void emplace_back(BOOST_FWD_REF(V) value) {
938+
check_low_capacity();
939+
circular_buffer<T, Alloc>::emplace_back(::boost::forward<V>(value));
940+
}
941+
#endif
942+
943+
//! Construct a new element at the beginning of the space optimized circular buffer.
944+
/*!
945+
\post if <code>capacity().%capacity() > 0</code> then <code>front() == item</code><br>
946+
If the <code>circular_buffer_space_optimized</code> is full, the last element will be removed. If the
947+
capacity is <code>0</code>, nothing will be inserted.<br><br>
948+
The amount of allocated memory in the internal buffer may be predictively increased.
949+
\param item The element to be inserted.
950+
\throws "An allocation error" if memory is exhausted (<code>std::bad_alloc</code> if the standard allocator is
951+
used).
952+
Whatever <code>T::T(Args...)</code> throws or nothing if <code>T::T(T&&)</code> is noexcept.
953+
Whatever <code>T::operator = (T&&)</code> throws.
954+
\par Exception Safety
955+
Basic.
956+
\par Iterator Invalidation
957+
Invalidates all iterators pointing to the <code>circular_buffer_space_optimized</code> (except iterators
958+
equal to <code>end()</code>).
959+
\par Complexity
960+
Linear (in the size of the <code>circular_buffer_space_optimized</code>).
961+
\sa <code>\link push_back() push_back(const_reference)\endlink</code>, <code>pop_back()</code>,
962+
<code>pop_front()</code>
963+
*/
964+
#ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES
965+
template <class ...Args>
966+
void emplace_front(BOOST_FWD_REF(Args) ...args) {
967+
check_low_capacity();
968+
circular_buffer<T, Alloc>::emplace_front(::boost::forward<Args>(args)...);
969+
}
970+
#else
971+
template <class V>
972+
void emplace_front(BOOST_FWD_REF(V) value) {
973+
check_low_capacity();
974+
circular_buffer<T, Alloc>::emplace_front(::boost::forward<V>(value));
975+
}
976+
#endif
977+
908978
//! Remove the last element from the space optimized circular buffer.
909979
/*!
910980
\pre <code>!empty()</code>

0 commit comments

Comments
 (0)