From df790ee29f813c3ed856fba4bc1f35f5b77bd034 Mon Sep 17 00:00:00 2001 From: Alexander van Gessel Date: Sat, 11 Nov 2017 00:14:51 +0100 Subject: [PATCH 1/7] Add emplace_{back,front} to circular_buffer --- include/boost/circular_buffer/base.hpp | 134 +++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/include/boost/circular_buffer/base.hpp b/include/boost/circular_buffer/base.hpp index 47441544..a039b598 100644 --- a/include/boost/circular_buffer/base.hpp +++ b/include/boost/circular_buffer/base.hpp @@ -1454,6 +1454,82 @@ private empty_value BOOST_CATCH_END } +#ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES + template + void emplace_back_impl(BOOST_FWD_REF(Args) ...args) { + if (full()) { + if (empty()) + return; + replace(m_last, value_type(::boost::forward(args)...)); + increment(m_last); + m_first = m_last; + } else { + cb_details::allocator_traits::construct(alloc(), boost::to_address(m_last), ::boost::forward(args)...); + increment(m_last); + ++m_size; + } + } +#else + template + void emplace_back_impl(BOOST_FWD_REF(V) value) { + if (full()) { + if (empty()) + return; + replace(m_last, value_type(::boost::forward(value))); + increment(m_last); + m_first = m_last; + } else { + cb_details::allocator_traits::construct(alloc(), boost::to_address(m_last), ::boost::forward(value)); + increment(m_last); + ++m_size; + } + } +#endif + +#ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES + template + void emplace_front_impl(BOOST_FWD_REF(Args) ...args) { + BOOST_TRY { + if (full()) { + if (empty()) + return; + decrement(m_first); + replace(m_first, value_type(::boost::forward(args)...)); + m_last = m_first; + } else { + decrement(m_first); + cb_details::allocator_traits::construct(alloc(), boost::to_address(m_first), ::boost::forward(args)...); + ++m_size; + } + } BOOST_CATCH(...) { + increment(m_first); + BOOST_RETHROW + } + BOOST_CATCH_END + } +#else + template + void emplace_front_impl(BOOST_FWD_REF(V) value) { + BOOST_TRY { + if (full()) { + if (empty()) + return; + decrement(m_first); + replace(m_first, value_type(::boost::forward(value))); + m_last = m_first; + } else { + decrement(m_first); + cb_details::allocator_traits::construct(alloc(), boost::to_address(m_first), ::boost::forward(value)); + ++m_size; + } + } BOOST_CATCH(...) { + increment(m_first); + BOOST_RETHROW + } + BOOST_CATCH_END + } +#endif + public: //! Insert a new element at the end of the circular_buffer. /*! @@ -1583,6 +1659,64 @@ private empty_value push_front(boost::move(temp)); } + //! Construct a new element at the end of the circular_buffer. + /*! + \post if capacity() > 0 then back() == item
+ If the circular_buffer is full, the first element will be removed. If the capacity is + 0, nothing will be inserted. + \param item The element to be inserted. + \throws Whatever T::T(Args...) throws. + Whatever T::operator = (T&&) throws. + \par Exception Safety + Basic; no-throw if the operation in the Throws section does not throw anything. + \par Iterator Invalidation + Does not invalidate any iterators with the exception of iterators pointing to the overwritten element. + \par Complexity + Constant (in the size of the circular_buffer). + \sa \link push_back() push_back(const_reference)\endlink, + pop_back(), emplace_front() + */ +#ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES + template + void emplace_back(BOOST_FWD_REF(Args) ...args) { + emplace_back_impl(::boost::forward(args)...); + } +#else + template + void emplace_back(BOOST_FWD_REF(V) value) { + emplace_back_impl(::boost::forward(value)); + } +#endif + + //! Construct a new element at the beginning of the circular_buffer. + /*! + \post if capacity() > 0 then back() == item
+ If the circular_buffer is full, the last element will be removed. If the capacity is + 0, nothing will be inserted. + \param item The element to be inserted. + \throws Whatever T::T(Args...) throws. + Whatever T::operator = (T&&) throws. + \par Exception Safety + Basic; no-throw if the operation in the Throws section does not throw anything. + \par Iterator Invalidation + Does not invalidate any iterators with the exception of iterators pointing to the overwritten element. + \par Complexity + Constant (in the size of the circular_buffer). + \sa \link push_front() push_front(const_reference)\endlink, + pop_front(), emplace_back() + */ +#ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES + template + void emplace_front(BOOST_FWD_REF(Args) ...args) { + emplace_front_impl(::boost::forward(args)...); + } +#else + template + void emplace_front(BOOST_FWD_REF(V) value) { + emplace_front_impl(::boost::forward(value)); + } +#endif + //! Remove the last element from the circular_buffer. /*! \pre !empty() From c7c0d4ac8135a8d1879dc6e97d4a0753b5ba5c0c Mon Sep 17 00:00:00 2001 From: Alexander van Gessel Date: Sat, 11 Nov 2017 00:15:08 +0100 Subject: [PATCH 2/7] Add emplace_{back,front} to circular_buffer_space_optimized --- .../boost/circular_buffer/space_optimized.hpp | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/include/boost/circular_buffer/space_optimized.hpp b/include/boost/circular_buffer/space_optimized.hpp index 21681fd3..81613d78 100644 --- a/include/boost/circular_buffer/space_optimized.hpp +++ b/include/boost/circular_buffer/space_optimized.hpp @@ -905,6 +905,76 @@ 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() + */ +#ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES + template + void emplace_back(BOOST_FWD_REF(Args) ...args) { + check_low_capacity(); + circular_buffer::emplace_back(::boost::forward(args)...); + } +#else + template + void emplace_back(BOOST_FWD_REF(V) value) { + check_low_capacity(); + circular_buffer::emplace_back(::boost::forward(value)); + } +#endif + + //! 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() + */ +#ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES + template + void emplace_front(BOOST_FWD_REF(Args) ...args) { + check_low_capacity(); + circular_buffer::emplace_front(::boost::forward(args)...); + } +#else + template + void emplace_front(BOOST_FWD_REF(V) value) { + check_low_capacity(); + circular_buffer::emplace_front(::boost::forward(value)); + } +#endif + //! Remove the last element from the space optimized circular buffer. /*! \pre !empty() From 90ef6257c4d96d24f1353a3f9052c2e08c78de5a Mon Sep 17 00:00:00 2001 From: Alexander van Gessel Date: Sat, 13 Oct 2018 15:13:50 +0200 Subject: [PATCH 3/7] Add tests for emplace_{back,front} --- test/common.ipp | 127 +++++++++++++++++++++++++++++------------------- 1 file changed, 77 insertions(+), 50 deletions(-) diff --git a/test/common.ipp b/test/common.ipp index 4d3d2790..358b28ba 100644 --- a/test/common.ipp +++ b/test/common.ipp @@ -283,6 +283,7 @@ void cxx11_allocator_test() { CB_CONTAINER > cb(10, 0); generic_test(cb); } + #endif void begin_and_end_test() { @@ -1153,6 +1154,32 @@ void pop_back_test() { generic_test(cb); } +void emplace_test(){ + CB_CONTAINER cb(4); + cb.emplace_back(4); + cb.emplace_back(5); + cb.emplace_back(6); + cb.emplace_back(7); + + BOOST_CHECK(cb.size() == 4); + BOOST_CHECK(cb.front() == 4); + BOOST_CHECK(cb.back() == 7); + + cb.emplace_front(3); + cb.emplace_front(2); + + BOOST_CHECK(cb.front() == 2); + BOOST_CHECK(cb.back() == 5); + + cb.emplace_front(1); + cb.emplace_front(0); + + BOOST_CHECK(cb.size() == 4); + BOOST_CHECK(*cb.begin() == 0); + BOOST_CHECK(cb.front() == 0); + BOOST_CHECK(cb.back() == 3); +} + void insert_test() { CB_CONTAINER cb1(4); @@ -2442,56 +2469,56 @@ void check_containers_exception_specifications() { } // add common tests into a test suite -void run_common_tests() -{ - basic_test(); - constructor_and_element_access_test(); - size_test(); - allocator_test(); - begin_and_end_test(); - rbegin_and_rend_test(); - element_access_and_insert_test(); - at_test(); - front_and_back_test(); - linearize_test(); - array_range_test(); - capacity_and_reserve_test(); - full_and_empty_test(); - set_capacity_test(); - rset_capacity_test(); - resize_test(); - rresize_test(); - constructor_test(); - assign_test(); - copy_constructor_and_assign_test(); - swap_test(); - push_back_test(); - pop_back_test(); - insert_test(); - insert_n_test(); - insert_range_test(); - push_front_test(); - pop_front_test(); - rinsert_test(); - rinsert_n_test(); - rinsert_range_test(); - erase_test(); - erase_range_test(); - rerase_test(); - rerase_range_test(); - clear_test(); - equality_test(); - lexicographical_comparison_test(); - assign_range_test(); - example_test(); - element_destruction_test(); - const_methods_test(); - rotate_test(); - move_container_on_cpp11(); - move_container_values_noexcept(); - check_containers_exception_specifications(); -#if !defined(BOOST_NO_CXX11_ALLOCATOR) - cxx11_allocator_test(); +void add_common_tests(test_suite* tests) { + tests->add(BOOST_TEST_CASE(&basic_test)); + tests->add(BOOST_TEST_CASE(&constructor_and_element_access_test)); + tests->add(BOOST_TEST_CASE(&size_test)); + tests->add(BOOST_TEST_CASE(&allocator_test)); + tests->add(BOOST_TEST_CASE(&begin_and_end_test)); + tests->add(BOOST_TEST_CASE(&rbegin_and_rend_test)); + tests->add(BOOST_TEST_CASE(&element_access_and_insert_test)); + tests->add(BOOST_TEST_CASE(&at_test)); + tests->add(BOOST_TEST_CASE(&front_and_back_test)); + tests->add(BOOST_TEST_CASE(&linearize_test)); + tests->add(BOOST_TEST_CASE(&array_range_test)); + tests->add(BOOST_TEST_CASE(&capacity_and_reserve_test)); + tests->add(BOOST_TEST_CASE(&full_and_empty_test)); + tests->add(BOOST_TEST_CASE(&set_capacity_test)); + tests->add(BOOST_TEST_CASE(&rset_capacity_test)); + tests->add(BOOST_TEST_CASE(&resize_test)); + tests->add(BOOST_TEST_CASE(&rresize_test)); + tests->add(BOOST_TEST_CASE(&constructor_test)); + tests->add(BOOST_TEST_CASE(&assign_test)); + tests->add(BOOST_TEST_CASE(©_constructor_and_assign_test)); + tests->add(BOOST_TEST_CASE(&swap_test)); + tests->add(BOOST_TEST_CASE(&push_back_test)); + tests->add(BOOST_TEST_CASE(&pop_back_test)); + tests->add(BOOST_TEST_CASE(&emplace_test)); + tests->add(BOOST_TEST_CASE(&insert_test)); + tests->add(BOOST_TEST_CASE(&insert_n_test)); + tests->add(BOOST_TEST_CASE(&insert_range_test)); + tests->add(BOOST_TEST_CASE(&push_front_test)); + tests->add(BOOST_TEST_CASE(&pop_front_test)); + tests->add(BOOST_TEST_CASE(&rinsert_test)); + tests->add(BOOST_TEST_CASE(&rinsert_n_test)); + tests->add(BOOST_TEST_CASE(&rinsert_range_test)); + tests->add(BOOST_TEST_CASE(&erase_test)); + tests->add(BOOST_TEST_CASE(&erase_range_test)); + tests->add(BOOST_TEST_CASE(&rerase_test)); + tests->add(BOOST_TEST_CASE(&rerase_range_test)); + tests->add(BOOST_TEST_CASE(&clear_test)); + tests->add(BOOST_TEST_CASE(&equality_test)); + tests->add(BOOST_TEST_CASE(&lexicographical_comparison_test)); + tests->add(BOOST_TEST_CASE(&assign_range_test)); + tests->add(BOOST_TEST_CASE(&example_test)); + tests->add(BOOST_TEST_CASE(&element_destruction_test)); + tests->add(BOOST_TEST_CASE(&const_methods_test)); + tests->add(BOOST_TEST_CASE(&rotate_test)); + tests->add(BOOST_TEST_CASE(&move_container_on_cpp11)); + tests->add(BOOST_TEST_CASE(&move_container_values_noexcept)); + tests->add(BOOST_TEST_CASE(&check_containers_exception_specifications)); +#if !defined(BOOST_CB_NO_CXX11_ALLOCATOR) + tests->add(BOOST_TEST_CASE(&cxx11_allocator_test)); #endif } From 19a1ce4ec20ac39f3073c1e8023fb8c2fb261cdf Mon Sep 17 00:00:00 2001 From: f9z Date: Fri, 13 May 2022 10:52:59 +1000 Subject: [PATCH 4/7] Revert "Add tests for emplace_{back,front}" This reverts commit 90ef6257c4d96d24f1353a3f9052c2e08c78de5a. --- test/common.ipp | 127 +++++++++++++++++++----------------------------- 1 file changed, 50 insertions(+), 77 deletions(-) diff --git a/test/common.ipp b/test/common.ipp index 358b28ba..4d3d2790 100644 --- a/test/common.ipp +++ b/test/common.ipp @@ -283,7 +283,6 @@ void cxx11_allocator_test() { CB_CONTAINER > cb(10, 0); generic_test(cb); } - #endif void begin_and_end_test() { @@ -1154,32 +1153,6 @@ void pop_back_test() { generic_test(cb); } -void emplace_test(){ - CB_CONTAINER cb(4); - cb.emplace_back(4); - cb.emplace_back(5); - cb.emplace_back(6); - cb.emplace_back(7); - - BOOST_CHECK(cb.size() == 4); - BOOST_CHECK(cb.front() == 4); - BOOST_CHECK(cb.back() == 7); - - cb.emplace_front(3); - cb.emplace_front(2); - - BOOST_CHECK(cb.front() == 2); - BOOST_CHECK(cb.back() == 5); - - cb.emplace_front(1); - cb.emplace_front(0); - - BOOST_CHECK(cb.size() == 4); - BOOST_CHECK(*cb.begin() == 0); - BOOST_CHECK(cb.front() == 0); - BOOST_CHECK(cb.back() == 3); -} - void insert_test() { CB_CONTAINER cb1(4); @@ -2469,56 +2442,56 @@ void check_containers_exception_specifications() { } // add common tests into a test suite -void add_common_tests(test_suite* tests) { - tests->add(BOOST_TEST_CASE(&basic_test)); - tests->add(BOOST_TEST_CASE(&constructor_and_element_access_test)); - tests->add(BOOST_TEST_CASE(&size_test)); - tests->add(BOOST_TEST_CASE(&allocator_test)); - tests->add(BOOST_TEST_CASE(&begin_and_end_test)); - tests->add(BOOST_TEST_CASE(&rbegin_and_rend_test)); - tests->add(BOOST_TEST_CASE(&element_access_and_insert_test)); - tests->add(BOOST_TEST_CASE(&at_test)); - tests->add(BOOST_TEST_CASE(&front_and_back_test)); - tests->add(BOOST_TEST_CASE(&linearize_test)); - tests->add(BOOST_TEST_CASE(&array_range_test)); - tests->add(BOOST_TEST_CASE(&capacity_and_reserve_test)); - tests->add(BOOST_TEST_CASE(&full_and_empty_test)); - tests->add(BOOST_TEST_CASE(&set_capacity_test)); - tests->add(BOOST_TEST_CASE(&rset_capacity_test)); - tests->add(BOOST_TEST_CASE(&resize_test)); - tests->add(BOOST_TEST_CASE(&rresize_test)); - tests->add(BOOST_TEST_CASE(&constructor_test)); - tests->add(BOOST_TEST_CASE(&assign_test)); - tests->add(BOOST_TEST_CASE(©_constructor_and_assign_test)); - tests->add(BOOST_TEST_CASE(&swap_test)); - tests->add(BOOST_TEST_CASE(&push_back_test)); - tests->add(BOOST_TEST_CASE(&pop_back_test)); - tests->add(BOOST_TEST_CASE(&emplace_test)); - tests->add(BOOST_TEST_CASE(&insert_test)); - tests->add(BOOST_TEST_CASE(&insert_n_test)); - tests->add(BOOST_TEST_CASE(&insert_range_test)); - tests->add(BOOST_TEST_CASE(&push_front_test)); - tests->add(BOOST_TEST_CASE(&pop_front_test)); - tests->add(BOOST_TEST_CASE(&rinsert_test)); - tests->add(BOOST_TEST_CASE(&rinsert_n_test)); - tests->add(BOOST_TEST_CASE(&rinsert_range_test)); - tests->add(BOOST_TEST_CASE(&erase_test)); - tests->add(BOOST_TEST_CASE(&erase_range_test)); - tests->add(BOOST_TEST_CASE(&rerase_test)); - tests->add(BOOST_TEST_CASE(&rerase_range_test)); - tests->add(BOOST_TEST_CASE(&clear_test)); - tests->add(BOOST_TEST_CASE(&equality_test)); - tests->add(BOOST_TEST_CASE(&lexicographical_comparison_test)); - tests->add(BOOST_TEST_CASE(&assign_range_test)); - tests->add(BOOST_TEST_CASE(&example_test)); - tests->add(BOOST_TEST_CASE(&element_destruction_test)); - tests->add(BOOST_TEST_CASE(&const_methods_test)); - tests->add(BOOST_TEST_CASE(&rotate_test)); - tests->add(BOOST_TEST_CASE(&move_container_on_cpp11)); - tests->add(BOOST_TEST_CASE(&move_container_values_noexcept)); - tests->add(BOOST_TEST_CASE(&check_containers_exception_specifications)); -#if !defined(BOOST_CB_NO_CXX11_ALLOCATOR) - tests->add(BOOST_TEST_CASE(&cxx11_allocator_test)); +void run_common_tests() +{ + basic_test(); + constructor_and_element_access_test(); + size_test(); + allocator_test(); + begin_and_end_test(); + rbegin_and_rend_test(); + element_access_and_insert_test(); + at_test(); + front_and_back_test(); + linearize_test(); + array_range_test(); + capacity_and_reserve_test(); + full_and_empty_test(); + set_capacity_test(); + rset_capacity_test(); + resize_test(); + rresize_test(); + constructor_test(); + assign_test(); + copy_constructor_and_assign_test(); + swap_test(); + push_back_test(); + pop_back_test(); + insert_test(); + insert_n_test(); + insert_range_test(); + push_front_test(); + pop_front_test(); + rinsert_test(); + rinsert_n_test(); + rinsert_range_test(); + erase_test(); + erase_range_test(); + rerase_test(); + rerase_range_test(); + clear_test(); + equality_test(); + lexicographical_comparison_test(); + assign_range_test(); + example_test(); + element_destruction_test(); + const_methods_test(); + rotate_test(); + move_container_on_cpp11(); + move_container_values_noexcept(); + check_containers_exception_specifications(); +#if !defined(BOOST_NO_CXX11_ALLOCATOR) + cxx11_allocator_test(); #endif } From e5b44b10b5ecaeb2cabd833541d68c267ae130ca Mon Sep 17 00:00:00 2001 From: f9z Date: Fri, 13 May 2022 11:22:03 +1000 Subject: [PATCH 5/7] add emplace_test --- test/common.ipp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/common.ipp b/test/common.ipp index 4d3d2790..22b85e9e 100644 --- a/test/common.ipp +++ b/test/common.ipp @@ -1153,6 +1153,32 @@ void pop_back_test() { generic_test(cb); } +void emplace_test(){ + CB_CONTAINER cb(4); + cb.emplace_back(4); + cb.emplace_back(5); + cb.emplace_back(6); + cb.emplace_back(7); + + BOOST_CHECK(cb.size() == 4); + BOOST_CHECK(cb.front() == 4); + BOOST_CHECK(cb.back() == 7); + + cb.emplace_front(3); + cb.emplace_front(2); + + BOOST_CHECK(cb.front() == 2); + BOOST_CHECK(cb.back() == 5); + + cb.emplace_front(1); + cb.emplace_front(0); + + BOOST_CHECK(cb.size() == 4); + BOOST_CHECK(*cb.begin() == 0); + BOOST_CHECK(cb.front() == 0); + BOOST_CHECK(cb.back() == 3); +} + void insert_test() { CB_CONTAINER cb1(4); @@ -2467,6 +2493,7 @@ void run_common_tests() swap_test(); push_back_test(); pop_back_test(); + emplace_test(); insert_test(); insert_n_test(); insert_range_test(); From d5819ae49b144b92cac314b18fc4d92236c4bbc6 Mon Sep 17 00:00:00 2001 From: f9z Date: Fri, 13 May 2022 12:32:40 +1000 Subject: [PATCH 6/7] finalise rebase --- include/boost/circular_buffer/base.hpp | 10 +++++----- test/common.ipp | 18 +++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/include/boost/circular_buffer/base.hpp b/include/boost/circular_buffer/base.hpp index a039b598..5ed13212 100644 --- a/include/boost/circular_buffer/base.hpp +++ b/include/boost/circular_buffer/base.hpp @@ -1429,7 +1429,7 @@ private empty_value boost::allocator_construct(alloc(), boost::to_address(m_last), static_cast(item)); increment(m_last); ++m_size; - } + } } /*! INTERNAL ONLY */ @@ -1464,7 +1464,7 @@ private empty_value increment(m_last); m_first = m_last; } else { - cb_details::allocator_traits::construct(alloc(), boost::to_address(m_last), ::boost::forward(args)...); + boost::allocator_construct(alloc(), boost::to_address(m_last), ::boost::forward(args)...); increment(m_last); ++m_size; } @@ -1479,7 +1479,7 @@ private empty_value increment(m_last); m_first = m_last; } else { - cb_details::allocator_traits::construct(alloc(), boost::to_address(m_last), ::boost::forward(value)); + boost::allocator_construct(alloc(), boost::to_address(m_last), ::boost::forward(value)); increment(m_last); ++m_size; } @@ -1498,7 +1498,7 @@ private empty_value m_last = m_first; } else { decrement(m_first); - cb_details::allocator_traits::construct(alloc(), boost::to_address(m_first), ::boost::forward(args)...); + boost::allocator_construct(alloc(), boost::to_address(m_first), ::boost::forward(args)...); ++m_size; } } BOOST_CATCH(...) { @@ -1519,7 +1519,7 @@ private empty_value m_last = m_first; } else { decrement(m_first); - cb_details::allocator_traits::construct(alloc(), boost::to_address(m_first), ::boost::forward(value)); + boost::allocator_construct(alloc(), boost::to_address(m_first), ::boost::forward(value)); ++m_size; } } BOOST_CATCH(...) { diff --git a/test/common.ipp b/test/common.ipp index 22b85e9e..0d99a685 100644 --- a/test/common.ipp +++ b/test/common.ipp @@ -1160,23 +1160,23 @@ void emplace_test(){ cb.emplace_back(6); cb.emplace_back(7); - BOOST_CHECK(cb.size() == 4); - BOOST_CHECK(cb.front() == 4); - BOOST_CHECK(cb.back() == 7); + BOOST_TEST(cb.size() == 4); + BOOST_TEST(cb.front() == 4); + BOOST_TEST(cb.back() == 7); cb.emplace_front(3); cb.emplace_front(2); - BOOST_CHECK(cb.front() == 2); - BOOST_CHECK(cb.back() == 5); + BOOST_TEST(cb.front() == 2); + BOOST_TEST(cb.back() == 5); cb.emplace_front(1); cb.emplace_front(0); - BOOST_CHECK(cb.size() == 4); - BOOST_CHECK(*cb.begin() == 0); - BOOST_CHECK(cb.front() == 0); - BOOST_CHECK(cb.back() == 3); + BOOST_TEST(cb.size() == 4); + BOOST_TEST(*cb.begin() == 0); + BOOST_TEST(cb.front() == 0); + BOOST_TEST(cb.back() == 3); } void insert_test() { From c4c85d730dc8e31c4d50aa45ada146ce8c2f5340 Mon Sep 17 00:00:00 2001 From: f9z Date: Fri, 13 May 2022 12:50:41 +1000 Subject: [PATCH 7/7] replace replace() with destroy_item() + construct() --- include/boost/circular_buffer/base.hpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/include/boost/circular_buffer/base.hpp b/include/boost/circular_buffer/base.hpp index 5ed13212..113fb661 100644 --- a/include/boost/circular_buffer/base.hpp +++ b/include/boost/circular_buffer/base.hpp @@ -1460,7 +1460,8 @@ private empty_value if (full()) { if (empty()) return; - replace(m_last, value_type(::boost::forward(args)...)); + destroy_item(m_last); + boost::allocator_construct(alloc(), boost::to_address(m_last), ::boost::forward(args)...); increment(m_last); m_first = m_last; } else { @@ -1475,7 +1476,8 @@ private empty_value if (full()) { if (empty()) return; - replace(m_last, value_type(::boost::forward(value))); + destroy_item(m_last); + boost::allocator_construct(alloc(), boost::to_address(m_last), ::boost::forward(args)...); increment(m_last); m_first = m_last; } else { @@ -1494,7 +1496,8 @@ private empty_value if (empty()) return; decrement(m_first); - replace(m_first, value_type(::boost::forward(args)...)); + destroy_item(m_first); + boost::allocator_construct(alloc(), boost::to_address(m_first), ::boost::forward(args)...); m_last = m_first; } else { decrement(m_first); @@ -1515,7 +1518,8 @@ private empty_value if (empty()) return; decrement(m_first); - replace(m_first, value_type(::boost::forward(value))); + destroy_item(m_first); + boost::allocator_construct(alloc(), boost::to_address(m_first), ::boost::forward(args)...); m_last = m_first; } else { decrement(m_first);