1212#include < __algorithm/copy.h>
1313#include < __algorithm/copy_n.h>
1414#include < __algorithm/fill_n.h>
15+ #include < __algorithm/iterator_operations.h>
1516#include < __algorithm/max.h>
1617#include < __algorithm/min.h>
1718#include < __algorithm/move.h>
1819#include < __algorithm/move_backward.h>
19- #include < __algorithm/ranges_copy_n.h>
2020#include < __algorithm/rotate.h>
2121#include < __assert>
2222#include < __config>
@@ -314,15 +314,15 @@ class vector {
314314 is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
315315 int > = 0 >
316316 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign (_ForwardIterator __first, _ForwardIterator __last) {
317- __assign_with_size (__first, __last, std::distance (__first, __last));
317+ __assign_with_size<_ClassicAlgPolicy> (__first, __last, std::distance (__first, __last));
318318 }
319319
320320#if _LIBCPP_STD_VER >= 23
321321 template <_ContainerCompatibleRange<_Tp> _Range>
322322 _LIBCPP_HIDE_FROM_ABI constexpr void assign_range (_Range&& __range) {
323323 if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
324324 auto __n = static_cast <size_type>(ranges::distance (__range));
325- __assign_with_size (ranges::begin (__range), ranges::end (__range), __n);
325+ __assign_with_size<_RangeAlgPolicy> (ranges::begin (__range), ranges::end (__range), __n);
326326
327327 } else {
328328 __assign_with_sentinel (ranges::begin (__range), ranges::end (__range));
@@ -518,15 +518,15 @@ class vector {
518518 int > = 0 >
519519 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
520520 insert (const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) {
521- return __insert_with_size (__position, __first, __last, std::distance (__first, __last));
521+ return __insert_with_size<_ClassicAlgPolicy> (__position, __first, __last, std::distance (__first, __last));
522522 }
523523
524524#if _LIBCPP_STD_VER >= 23
525525 template <_ContainerCompatibleRange<_Tp> _Range>
526526 _LIBCPP_HIDE_FROM_ABI constexpr iterator insert_range (const_iterator __position, _Range&& __range) {
527527 if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
528528 auto __n = static_cast <size_type>(ranges::distance (__range));
529- return __insert_with_size (__position, ranges::begin (__range), ranges::end (__range), __n);
529+ return __insert_with_size<_RangeAlgPolicy> (__position, ranges::begin (__range), ranges::end (__range), __n);
530530
531531 } else {
532532 return __insert_with_sentinel (__position, ranges::begin (__range), ranges::end (__range));
@@ -619,12 +619,13 @@ class vector {
619619 // The `_Iterator` in `*_with_size` functions can be input-only only if called from `*_range` (since C++23).
620620 // Otherwise, `_Iterator` is a forward iterator.
621621
622- template <class _Iterator , class _Sentinel >
622+ template <class _AlgPolicy , class _Iterator , class _Sentinel >
623623 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
624624 __assign_with_size (_Iterator __first, _Sentinel __last, difference_type __n);
625625
626- template <class _Iterator ,
627- __enable_if_t <!is_same<decltype (*std::declval<_Iterator&>())&&, value_type&&>::value, int > = 0 >
626+ template <class _AlgPolicy ,
627+ class _Iterator ,
628+ __enable_if_t <!is_same<__policy_value_type<_AlgPolicy, _Iterator>, value_type>::value, int > = 0 >
628629 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
629630 __insert_assign_n_unchecked (_Iterator __first, difference_type __n, pointer __position) {
630631 for (pointer __end_position = __position + __n; __position != __end_position; ++__position, (void )++__first) {
@@ -633,25 +634,19 @@ class vector {
633634 }
634635 }
635636
636- template <class _Iterator ,
637- __enable_if_t <is_same<decltype (*std::declval<_Iterator&>())&&, value_type&&>::value, int > = 0 >
637+ template <class _AlgPolicy ,
638+ class _Iterator ,
639+ __enable_if_t <is_same<__policy_value_type<_AlgPolicy, _Iterator>, value_type>::value, int > = 0 >
638640 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
639641 __insert_assign_n_unchecked (_Iterator __first, difference_type __n, pointer __position) {
640- #if _LIBCPP_STD_VER >= 23
641- if constexpr (!forward_iterator<_Iterator>) { // Handles input-only sized ranges for insert_range
642- ranges::copy_n (std::move (__first), __n, __position);
643- } else
644- #endif
645- {
646- std::copy_n (__first, __n, __position);
647- }
642+ std::__copy_n<_AlgPolicy>(std::move (__first), __n, __position);
648643 }
649644
650645 template <class _InputIterator , class _Sentinel >
651646 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
652647 __insert_with_sentinel (const_iterator __position, _InputIterator __first, _Sentinel __last);
653648
654- template <class _Iterator , class _Sentinel >
649+ template <class _AlgPolicy , class _Iterator , class _Sentinel >
655650 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
656651 __insert_with_size (const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n);
657652
@@ -1039,20 +1034,14 @@ vector<_Tp, _Allocator>::__assign_with_sentinel(_Iterator __first, _Sentinel __l
10391034}
10401035
10411036template <class _Tp , class _Allocator >
1042- template <class _Iterator , class _Sentinel >
1037+ template <class _AlgPolicy , class _Iterator , class _Sentinel >
10431038_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
10441039vector<_Tp, _Allocator>::__assign_with_size(_Iterator __first, _Sentinel __last, difference_type __n) {
10451040 size_type __new_size = static_cast <size_type>(__n);
10461041 if (__new_size <= capacity ()) {
10471042 if (__new_size > size ()) {
1048- #if _LIBCPP_STD_VER >= 23
1049- auto __mid = ranges::copy_n (std::move (__first), size (), this ->__begin_ ).in ;
1043+ auto __mid = std::__copy_n<_AlgPolicy>(std::move (__first), size (), this ->__begin_ ).first ;
10501044 __construct_at_end (std::move (__mid), std::move (__last), __new_size - size ());
1051- #else
1052- _Iterator __mid = std::next (__first, size ());
1053- std::copy (__first, __mid, this ->__begin_ );
1054- __construct_at_end (__mid, __last, __new_size - size ());
1055- #endif
10561045 } else {
10571046 pointer __m = std::__copy (std::move (__first), __last, this ->__begin_ ).second ;
10581047 this ->__destruct_at_end (__m);
@@ -1326,7 +1315,7 @@ vector<_Tp, _Allocator>::__insert_with_sentinel(const_iterator __position, _Inpu
13261315}
13271316
13281317template <class _Tp , class _Allocator >
1329- template <class _Iterator , class _Sentinel >
1318+ template <class _AlgPolicy , class _Iterator , class _Sentinel >
13301319_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI typename vector<_Tp, _Allocator>::iterator
13311320vector<_Tp, _Allocator>::__insert_with_size (
13321321 const_iterator __position, _Iterator __first, _Sentinel __last, difference_type __n) {
@@ -1347,12 +1336,12 @@ vector<_Tp, _Allocator>::__insert_with_size(
13471336 __construct_at_end (__m, __last, __n - __dx);
13481337 if (__dx > 0 ) {
13491338 __move_range (__p, __old_last, __p + __n);
1350- __insert_assign_n_unchecked (__first, __dx, __p);
1339+ __insert_assign_n_unchecked<_AlgPolicy> (__first, __dx, __p);
13511340 }
13521341 }
13531342 } else {
13541343 __move_range (__p, __old_last, __p + __n);
1355- __insert_assign_n_unchecked (std::move (__first), __n, __p);
1344+ __insert_assign_n_unchecked<_AlgPolicy> (std::move (__first), __n, __p);
13561345 }
13571346 } else {
13581347 __split_buffer<value_type, allocator_type&> __v (__recommend (size () + __n), __p - this ->__begin_ , this ->__alloc_ );
0 commit comments