Skip to content

Commit 26fdeab

Browse files
committed
improve vector move ctor
1 parent 530bdc5 commit 26fdeab

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

stl/inc/vector

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,10 @@ public:
372372
using reference = value_type&;
373373
using const_reference = const value_type&;
374374

375-
_Vector_val() noexcept : _Myfirst(), _Mylast(), _Myend() {}
375+
_Vector_val() noexcept : _Myfirst{}, _Mylast{}, _Myend{} {}
376+
377+
_Vector_val(pointer _First, pointer _Last, pointer _End) noexcept
378+
: _Myfirst{_First}, _Mylast{_Last}, _Myend{_End} {}
376379

377380
void _Swap_val(_Vector_val& _Right) noexcept {
378381
this->_Swap_proxy_and_iterators(_Right);
@@ -578,9 +581,15 @@ private:
578581
}
579582

580583
public:
581-
vector(vector&& _Right) noexcept : _Mypair(_One_then_variadic_args_t{}, _STD move(_Right._Getal())) {
584+
vector(vector&& _Right) noexcept
585+
: _Mypair(_One_then_variadic_args_t{}, _STD move(_Right._Getal()), _Right._Mypair._Myval2._Myfirst,
586+
_Right._Mypair._Myval2._Mylast, _Right._Mypair._Myval2._Myend) {
582587
_Mypair._Myval2._Alloc_proxy(_GET_PROXY_ALLOCATOR(_Alty, _Getal()));
583-
_Move_construct(_Right, true_type{});
588+
_Mypair._Myval2._Swap_proxy_and_iterators(_Right._Mypair._Myval2);
589+
590+
_Right._Mypair._Myval2._Myfirst = pointer();
591+
_Right._Mypair._Myval2._Mylast = pointer();
592+
_Right._Mypair._Myval2._Myend = pointer();
584593
}
585594

586595
vector(vector&& _Right, const _Alloc& _Al) noexcept(_Alty_traits::is_always_equal::value) // strengthened

0 commit comments

Comments
 (0)