Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix constexpr vector again #2161

Merged
merged 9 commits into from
Sep 11, 2021
Merged
138 changes: 57 additions & 81 deletions stl/inc/vector
Original file line number Diff line number Diff line change
Expand Up @@ -570,13 +570,27 @@ public:
return *this;
}

if (_Getal() == _Right._Getal()) {
_Tidy();
_Pocma(_Getal(), _Right._Getal());
_Mypair._Myval2._Take_contents(_Right._Mypair._Myval2);
} else if constexpr (!is_same_v<_Choose_pocma<_Alty>, _Equal_allocators>) {
_Move_assign_unequal_alloc(_Right);
_Alty& _Al = _Getal();
_Alty& _Right_al = _Right._Getal();
if constexpr (is_same_v<_Choose_pocma<_Alty>, _No_propagate_allocators>) {
if (_Al != _Right_al) {
_Move_assign_unequal_alloc(_Right);
return *this;
}
}

_Tidy();
#if _ITERATOR_DEBUG_LEVEL != 0
if constexpr (is_same_v<_Choose_pocma<_Alty>, _Propagate_allocators>) {
if (_Al != _Right_al) {
// intentionally slams into noexcept on OOM, TRANSITION, VSO-466800
_Mypair._Myval2._Reload_proxy(_GET_PROXY_ALLOCATOR(_Alty, _Al), _GET_PROXY_ALLOCATOR(_Alty, _Right_al));
}
}
#endif // _ITERATOR_DEBUG_LEVEL != 0

_Pocma(_Al, _Right_al);
_Mypair._Myval2._Take_contents(_Right._Mypair._Myval2);
return *this;
}

Expand Down Expand Up @@ -969,17 +983,16 @@ public:
pointer& _Mylast = _My_data._Mylast;

_My_data._Orphan_all();
const auto _Oldcapacity = static_cast<size_type>(_My_data._Myend - _Myfirst);
if (_Newsize > _Oldcapacity) { // reallocate
_Clear_and_reserve_geometric(_Newsize);
_Mylast = _Uninitialized_fill_n(_Myfirst, _Newsize, _Val, _Al);
return;
}

auto _Oldsize = static_cast<size_type>(_Mylast - _Myfirst);
const auto _Oldsize = static_cast<size_type>(_Mylast - _Myfirst);
if (_Newsize > _Oldsize) {
const auto _Oldcapacity = static_cast<size_type>(_My_data._Myend - _Myfirst);
if (_Newsize > _Oldcapacity) { // reallocate
_Clear_and_reserve_geometric(_Newsize);
_Oldsize = 0;
} else {
_STD fill(_Myfirst, _Mylast, _Val);
}

_STD fill(_Myfirst, _Mylast, _Val);
_Mylast = _Uninitialized_fill_n(_Mylast, _Newsize - _Oldsize, _Val, _Al);
} else {
const pointer _Newlast = _Myfirst + _Newsize;
Expand Down Expand Up @@ -1031,32 +1044,15 @@ private:
pointer& _Myend = _My_data._Myend;

_My_data._Orphan_all();

if constexpr (conjunction_v<bool_constant<_Ptr_copy_cat<_Iter, _Ty*>::_Trivially_copyable>,
_Uses_default_construct<_Alty, _Ty*, decltype(*_First)>,
_Uses_default_destroy<_Alty, _Ty*>>) {
#if _HAS_CXX20
if (!_STD is_constant_evaluated())
#endif // _HAS_CXX20
{
const auto _Oldcapacity = static_cast<size_type>(_Myend - _Myfirst);
if (_Newsize > _Oldcapacity) {
_Clear_and_reserve_geometric(_Newsize);
}

_Mylast = _Refancy<pointer>(_Copy_memmove(_First, _Last, _Unfancy(_Myfirst)));
return;
}
const auto _Oldcapacity = static_cast<size_type>(_Myend - _Myfirst);
if (_Newsize > _Oldcapacity) {
_Clear_and_reserve_geometric(_Newsize);
_Mylast = _Uninitialized_copy(_First, _Last, _Myfirst, _Al);
return;
}
auto _Oldsize = static_cast<size_type>(_Mylast - _Myfirst);

const auto _Oldsize = static_cast<size_type>(_Mylast - _Myfirst);
if (_Newsize > _Oldsize) {
const auto _Oldcapacity = static_cast<size_type>(_Myend - _Myfirst);
if (_Newsize > _Oldcapacity) { // reallocate
_Clear_and_reserve_geometric(_Newsize);
_Oldsize = 0;
}

// performance note: traversing [_First, _Mid) twice
const _Iter _Mid = _STD next(_First, static_cast<difference_type>(_Oldsize));
_Copy_unchecked(_First, _Mid, _Myfirst);
Expand Down Expand Up @@ -1668,56 +1664,36 @@ private:
_Proxy._Release();
}

_CONSTEXPR20 void _Move_assign_unequal_alloc(vector& _Right) noexcept(
!is_same_v<_Choose_pocma<_Alty>, _No_propagate_allocators>) {
_CONSTEXPR20 void _Move_assign_unequal_alloc(vector& _Right) {
auto& _Al = _Getal();
auto& _My_data = _Mypair._Myval2;
auto& _Right_data = _Right._Mypair._Myval2;
if constexpr (is_same_v<_Choose_pocma<_Alty>, _Propagate_allocators>) {
_Tidy();
#if _ITERATOR_DEBUG_LEVEL != 0
// intentionally slams into noexcept on OOM, TRANSITION, VSO-466800
_My_data._Reload_proxy(_GET_PROXY_ALLOCATOR(_Alty, _Al), _GET_PROXY_ALLOCATOR(_Alty, _Right._Getal()));
#endif // _ITERATOR_DEBUG_LEVEL != 0
_Pocma(_Al, _Right._Getal());
_My_data._Take_contents(_Right_data);
} else {
const pointer _First = _Right_data._Myfirst;
const pointer _Last = _Right_data._Mylast;
const auto _Newsize = static_cast<size_type>(_Last - _First);

pointer& _Myfirst = _My_data._Myfirst;
pointer& _Mylast = _My_data._Mylast;
const pointer _First = _Right_data._Myfirst;
const pointer _Last = _Right_data._Mylast;
const auto _Newsize = static_cast<size_type>(_Last - _First);

_My_data._Orphan_all();

const auto _Oldcapacity = static_cast<size_type>(_My_data._Myend - _Myfirst);
if constexpr (conjunction_v<bool_constant<_Ptr_copy_cat<_Ty*, _Ty*>::_Trivially_copyable>,
_Uses_default_construct<_Alty, _Ty*, _Ty>, _Uses_default_destroy<_Alty, _Ty*>>) {
if (_Newsize > _Oldcapacity) {
_Clear_and_reserve_geometric(_Newsize);
}

_Mylast = _Refancy<pointer>(_Copy_memmove(_Unfancy(_First), _Unfancy(_Last), _Unfancy(_Myfirst)));
} else {
auto _Oldsize = static_cast<size_type>(_Mylast - _Myfirst);
pointer& _Myfirst = _My_data._Myfirst;
pointer& _Mylast = _My_data._Mylast;

if (_Newsize > _Oldsize) {
if (_Newsize > _Oldcapacity) { // reallocate
_Clear_and_reserve_geometric(_Newsize);
_Oldsize = 0;
}
_My_data._Orphan_all();
const auto _Oldcapacity = static_cast<size_type>(_My_data._Myend - _Myfirst);
if (_Newsize > _Oldcapacity) {
_Clear_and_reserve_geometric(_Newsize);
_Mylast = _Uninitialized_move(_First, _Last, _Myfirst, _Al);
return;
}

const pointer _Mid = _First + _Oldsize;
_Move_unchecked(_First, _Mid, _Myfirst);
_Mylast = _Uninitialized_move(_Mid, _Last, _Mylast, _Al);
} else {
const pointer _Newlast = _Myfirst + _Newsize;
_Move_unchecked(_First, _Last, _Myfirst);
_Destroy_range(_Newlast, _Mylast, _Al);
_Mylast = _Newlast;
}
}
const auto _Oldsize = static_cast<size_type>(_Mylast - _Myfirst);
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
if (_Newsize > _Oldsize) {
const pointer _Mid = _First + _Oldsize;
_Move_unchecked(_First, _Mid, _Myfirst);
_Mylast = _Uninitialized_move(_Mid, _Last, _Mylast, _Al);
} else {
const pointer _Newlast = _Myfirst + _Newsize;
_Move_unchecked(_First, _Last, _Myfirst);
_Destroy_range(_Newlast, _Mylast, _Al);
_Mylast = _Newlast;
}
}

Expand Down
Loading