@@ -1360,27 +1360,25 @@ vector<_Tp, _Allocator>::__insert_with_sentinel(const_iterator __position, _Inpu
13601360 for (; this ->__end_ != this ->__end_cap () && __first != __last; ++__first) {
13611361 __construct_one_at_end (*__first);
13621362 }
1363- __split_buffer<value_type, allocator_type&> __v (__a);
1364- if (__first != __last) {
1365- # if _LIBCPP_HAS_EXCEPTIONS
1366- try {
1367- #endif // _LIBCPP_HAS_EXCEPTIONS
1368- __v. __construct_at_end_with_sentinel ( std::move (__first), std::move (__last) );
1369- difference_type __old_size = __old_last - this -> __begin_ ;
1370- difference_type __old_p = __p - this -> __begin_ ;
1371- reserve ( __recommend ( size () + __v. size ()));
1372- __p = this -> __begin_ + __old_p ;
1373- __old_last = this -> __begin_ + __old_size ;
1374- # if _LIBCPP_HAS_EXCEPTIONS
1375- } catch (...) {
1376- erase ( __make_iter (__old_last), end ());
1377- throw ;
1378- }
1379- # endif // _LIBCPP_HAS_EXCEPTIONS
1363+ if (__first == __last)
1364+ std::rotate (__p, __old_last, this -> __end_ );
1365+ else {
1366+ auto __guard =
1367+ std::__make_exception_guard (_AllocatorDestroyRangeReverse<allocator_type, pointer>(__a, __old_last, __end_));
1368+ __split_buffer<value_type, allocator_type&> __v (__a );
1369+ __v. __construct_at_end_with_sentinel ( std::move (__first), std::move (__last)) ;
1370+ __split_buffer<value_type, allocator_type&> __merged ( __recommend ( size () + __v. size ()), __off, __a) ;
1371+ std::__uninitialized_allocator_relocate (
1372+ __a, std::__to_address (__old_last), std::__to_address (__end_), std::__to_address (__merged. __end_ )) ;
1373+ __merged. __end_ += __end_ - __old_last ;
1374+ __end_ = __old_last;
1375+ __guard. __complete ();
1376+ std::__uninitialized_allocator_relocate (
1377+ __a, std::__to_address (__v. __begin_ ), std::__to_address (__v. __end_ ), std::__to_address (__merged. __end_ )) ;
1378+ __merged. __end_ += __v. size ();
1379+ __p = __swap_out_circular_buffer (__merged, __p);
13801380 }
1381- __p = std::rotate (__p, __old_last, this ->__end_ );
1382- insert (__make_iter (__p), std::make_move_iterator (__v.begin ()), std::make_move_iterator (__v.end ()));
1383- return begin () + __off;
1381+ return __make_iter (__p);
13841382}
13851383
13861384template <class _Tp , class _Allocator >
0 commit comments