|
58 | 58 | #include <__type_traits/is_same.h>
|
59 | 59 | #include <__type_traits/is_trivially_relocatable.h>
|
60 | 60 | #include <__type_traits/type_identity.h>
|
| 61 | +#include <__utility/declval.h> |
61 | 62 | #include <__utility/exception_guard.h>
|
62 | 63 | #include <__utility/forward.h>
|
63 | 64 | #include <__utility/is_pointer_in_range.h>
|
@@ -602,6 +603,30 @@ class _LIBCPP_TEMPLATE_VIS vector {
|
602 | 603 | _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
|
603 | 604 | __assign_with_size(_Iterator __first, _Sentinel __last, difference_type __n);
|
604 | 605 |
|
| 606 | + template <class _Iterator, |
| 607 | + __enable_if_t<!is_same<decltype(*std::declval<_Iterator&>())&&, value_type&&>::value, int> = 0> |
| 608 | + _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void |
| 609 | + __insert_assign_n_unchecked(_Iterator __first, difference_type __n, pointer __position) { |
| 610 | + for (pointer __end_position = __position + __n; __position != __end_position; ++__position, (void)++__first) { |
| 611 | + __temp_value<value_type, _Allocator> __tmp(this->__alloc_, *__first); |
| 612 | + *__position = std::move(__tmp.get()); |
| 613 | + } |
| 614 | + } |
| 615 | + |
| 616 | + template <class _Iterator, |
| 617 | + __enable_if_t<is_same<decltype(*std::declval<_Iterator&>())&&, value_type&&>::value, int> = 0> |
| 618 | + _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void |
| 619 | + __insert_assign_n_unchecked(_Iterator __first, difference_type __n, pointer __position) { |
| 620 | +#if _LIBCPP_STD_VER >= 23 |
| 621 | + if constexpr (!forward_iterator<_Iterator>) { // Handles input-only sized ranges for insert_range |
| 622 | + ranges::copy_n(std::move(__first), __n, __position); |
| 623 | + } else |
| 624 | +#endif |
| 625 | + { |
| 626 | + std::copy_n(__first, __n, __position); |
| 627 | + } |
| 628 | + } |
| 629 | + |
605 | 630 | template <class _InputIterator, class _Sentinel>
|
606 | 631 | _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI iterator
|
607 | 632 | __insert_with_sentinel(const_iterator __position, _InputIterator __first, _Sentinel __last);
|
@@ -1322,19 +1347,12 @@ vector<_Tp, _Allocator>::__insert_with_size(
|
1322 | 1347 | __construct_at_end(__m, __last, __n - __dx);
|
1323 | 1348 | if (__dx > 0) {
|
1324 | 1349 | __move_range(__p, __old_last, __p + __n);
|
1325 |
| - std::copy(__first, __m, __p); |
| 1350 | + __insert_assign_n_unchecked(__first, __dx, __p); |
1326 | 1351 | }
|
1327 | 1352 | }
|
1328 | 1353 | } else {
|
1329 | 1354 | __move_range(__p, __old_last, __p + __n);
|
1330 |
| -#if _LIBCPP_STD_VER >= 23 |
1331 |
| - if constexpr (!forward_iterator<_Iterator>) { |
1332 |
| - ranges::copy_n(std::move(__first), __n, __p); |
1333 |
| - } else |
1334 |
| -#endif |
1335 |
| - { |
1336 |
| - std::copy_n(__first, __n, __p); |
1337 |
| - } |
| 1355 | + __insert_assign_n_unchecked(std::move(__first), __n, __p); |
1338 | 1356 | }
|
1339 | 1357 | } else {
|
1340 | 1358 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, this->__alloc_);
|
|
0 commit comments