From 9ad078f9b36971d365a1083754b998247373e0f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Sat, 6 Sep 2025 12:40:29 +0200 Subject: [PATCH] Add new algos and simplify template parameters --- .../boost/container/detail/copy_move_algo.hpp | 103 ++++++++++++++---- 1 file changed, 82 insertions(+), 21 deletions(-) diff --git a/include/boost/container/detail/copy_move_algo.hpp b/include/boost/container/detail/copy_move_algo.hpp index 7c7d216..2081d67 100644 --- a/include/boost/container/detail/copy_move_algo.hpp +++ b/include/boost/container/detail/copy_move_algo.hpp @@ -800,10 +800,9 @@ inline typename dtl::enable_if_memtransfer_copy_assignable::type template // F models ForwardIterator inline typename dtl::disable_if_memtransfer_copy_assignable::type - copy_n(I f, U n, F r) + copy_n(I f, std::size_t n, F r) { while (n) { --n; @@ -815,10 +814,9 @@ inline typename dtl::disable_if_memtransfer_copy_assignable::type template // F models ForwardIterator inline typename dtl::enable_if_memtransfer_copy_assignable::type - copy_n(I f, U n, F r) BOOST_NOEXCEPT_OR_NOTHROW + copy_n(I f, std::size_t n, F r) BOOST_NOEXCEPT_OR_NOTHROW { return dtl::memmove_n(f, n, r); } ////////////////////////////////////////////////////////////////////////////// @@ -829,10 +827,9 @@ inline typename dtl::enable_if_memtransfer_copy_assignable::type template // F models ForwardIterator inline typename dtl::disable_if_memtransfer_copy_assignable::type - copy_n_source(I f, U n, F r) + copy_n_source(I f, std::size_t n, F r) { while (n) { --n; @@ -910,10 +907,9 @@ inline typename dtl::enable_if_memtransfer_copy_assignable::type template // F models ForwardIterator inline typename dtl::disable_if_memtransfer_copy_assignable::type - move_n(I f, U n, F r) + move_n(I f, std::size_t n, F r) { while (n) { --n; @@ -925,13 +921,11 @@ inline typename dtl::disable_if_memtransfer_copy_assignable::type template // F models ForwardIterator inline typename dtl::enable_if_memtransfer_copy_assignable::type - move_n(I f, U n, F r) BOOST_NOEXCEPT_OR_NOTHROW + move_n(I f, std::size_t n, F r) BOOST_NOEXCEPT_OR_NOTHROW { return dtl::memmove_n(f, n, r); } - ////////////////////////////////////////////////////////////////////////////// // // move_backward @@ -966,6 +960,77 @@ inline typename dtl::enable_if_memtransfer_copy_assignable::type return r; } +////////////////////////////////////////////////////////////////////////////// +// +// move_backward_n +// +////////////////////////////////////////////////////////////////////////////// + +template + // F models ForwardIterator +inline typename dtl::disable_if_memtransfer_copy_assignable::type + move_backward_n(I l, std::size_t n, F r) +{ + while (n) { + --n; + --l; --r; + *r = ::boost::move(*l); + } + return r; +} + +template + // F models ForwardIterator +inline typename dtl::enable_if_memtransfer_copy_assignable::type + move_backward_n(I l, std::size_t n, F r) BOOST_NOEXCEPT_OR_NOTHROW +{ + typedef typename boost::container::iter_value::type value_type; + if (BOOST_LIKELY(n != 0)){ + r -= n; + std::memmove((boost::movelib::iterator_to_raw_pointer)(r), (boost::movelib::iterator_to_raw_pointer)(l) - n, sizeof(value_type)*n); + } + return r; +} + +////////////////////////////////////////////////////////////////////////////// +// +// move_backward_n_source +// +////////////////////////////////////////////////////////////////////////////// + +template + // F models ForwardIterator +inline typename dtl::disable_if_memtransfer_copy_assignable::type + move_backward_n_source(I l, std::size_t n, F r) +{ + while (n) { + --n; + --l; --r; + *r = ::boost::move(*l); + } + return l; +} + +template + // F models ForwardIterator +inline typename dtl::enable_if_memtransfer_copy_assignable::type + move_backward_n_source(I l, std::size_t n, F r) BOOST_NOEXCEPT_OR_NOTHROW +{ + typedef typename boost::container::iter_value::type value_type; + + if (BOOST_LIKELY(n != 0)){ + r -= n; + l -= n; + std::memmove((boost::movelib::iterator_to_raw_pointer)(r), l, sizeof(value_type)*n); + } + return l; +} + + ////////////////////////////////////////////////////////////////////////////// // // move_n_source_dest @@ -974,10 +1039,9 @@ inline typename dtl::enable_if_memtransfer_copy_assignable::type template // F models ForwardIterator inline typename dtl::disable_if_memtransfer_copy_assignable::type - move_n_source_dest(I f, U n, F &r) + move_n_source_dest(I f, std::size_t n, F &r) { while (n) { --n; @@ -1002,10 +1066,9 @@ inline typename dtl::enable_if_memtransfer_copy_assignable::type template // F models ForwardIterator inline typename dtl::disable_if_memtransfer_copy_assignable::type - move_n_source(I f, U n, F r) + move_n_source(I f, std::size_t n, F r) { while (n) { --n; @@ -1043,10 +1106,9 @@ inline B move_backward_overlapping(B f, B l, B rl) template // U models unsigned integral constant + ,typename I> // I models InputIterator inline typename dtl::disable_if_trivially_destructible::type - destroy_alloc_n(Allocator &a, I f, U n) + destroy_alloc_n(Allocator &a, I f, std::size_t n) { while(n){ --n; @@ -1057,10 +1119,9 @@ inline typename dtl::disable_if_trivially_destructible::type template // U models unsigned integral constant + ,typename I> // I models InputIterator inline typename dtl::enable_if_trivially_destructible::type - destroy_alloc_n(Allocator &, I, U) + destroy_alloc_n(Allocator &, I, std::size_t) {} //////////////////////////////////////////////////////////////////////////////