Skip to content

Replace _GET_PROXY_ALLOCATOR with a function template #5475

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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions stl/inc/forward_list
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ public:
if (_Al != _Right_al) {
_Mypair._Myval2._Orphan_all();
clear();
_Mypair._Myval2._Reload_proxy(_GET_PROXY_ALLOCATOR(_Alty, _Al), _GET_PROXY_ALLOCATOR(_Alty, _Right_al));
_Mypair._Myval2._Reload_proxy(_STD _Get_proxy_allocator(_Al), _Get_proxy_allocator(_Right_al));
_Pocma(_Al, _Right_al);
_Take_head(_Right);
return *this;
Expand Down Expand Up @@ -741,7 +741,7 @@ private:
public:
forward_list(initializer_list<_Ty> _Ilist, const _Alloc& _Al = allocator_type())
: _Mypair(_One_then_variadic_args_t{}, _Al) {
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Getal());
auto _Alproxy = _STD _Get_proxy_allocator(_Getal());
_Container_proxy_ptr<_Alty> _Proxy(_Alproxy, _Mypair._Myval2);
insert_after(before_begin(), _Ilist.begin(), _Ilist.end());
_Proxy._Release();
Expand All @@ -764,7 +764,7 @@ public:
~forward_list() noexcept {
clear();
#if _ITERATOR_DEBUG_LEVEL != 0 // TRANSITION, ABI
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alty, _Getal());
auto _Alproxy = _STD _Get_proxy_allocator(_Getal());
_Delete_plain_internal(_Alproxy, _Mypair._Myval2._Myproxy);
#endif // _ITERATOR_DEBUG_LEVEL != 0
}
Expand All @@ -780,8 +780,7 @@ public:
if (_Al != _Right_al) {
_Mypair._Myval2._Orphan_all();
clear();
_Mypair._Myval2._Reload_proxy(
_GET_PROXY_ALLOCATOR(_Alnode, _Al), _GET_PROXY_ALLOCATOR(_Alnode, _Right_al));
_Mypair._Myval2._Reload_proxy(_STD _Get_proxy_allocator(_Al), _STD _Get_proxy_allocator(_Right_al));
}
}

Expand Down Expand Up @@ -1551,7 +1550,7 @@ private:
}

void _Alloc_proxy() {
_Mypair._Myval2._Alloc_proxy(_GET_PROXY_ALLOCATOR(_Alnode, _Getal()));
_Mypair._Myval2._Alloc_proxy(_STD _Get_proxy_allocator(_Getal()));
}

void _Swap_proxy_and_iterators(forward_list& _Right) noexcept {
Expand Down
22 changes: 11 additions & 11 deletions stl/inc/list
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ private:
}

void _Construct_n(_CRT_GUARDOVERFLOW size_type _Count) {
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Getal());
auto _Alproxy = _STD _Get_proxy_allocator(_Getal());
_Container_proxy_ptr<_Alty> _Proxy(_Alproxy, _Mypair._Myval2);
_List_node_insert_op2<_Alnode> _Appended(_Getal());
_Appended._Append_n(_Count);
Expand All @@ -845,7 +845,7 @@ public:

private:
void _Construct_n(_CRT_GUARDOVERFLOW size_type _Count, const _Ty& _Val) {
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Getal());
auto _Alproxy = _STD _Get_proxy_allocator(_Getal());
_Container_proxy_ptr<_Alty> _Proxy(_Alproxy, _Mypair._Myval2);
_List_node_insert_op2<_Alnode> _Appended(_Getal());
_Appended._Append_n(_Count, _Val);
Expand All @@ -870,7 +870,7 @@ public:
private:
template <class _Iter, class _Sent>
void _Construct_range_unchecked(_Iter _First, const _Sent _Last) {
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Getal());
auto _Alproxy = _STD _Get_proxy_allocator(_Getal());
_Container_proxy_ptr<_Alty> _Proxy(_Alproxy, _Mypair._Myval2);
_List_node_insert_op2<_Alnode> _Appended(_Getal());
_Appended._Append_range_unchecked(_STD move(_First), _Last);
Expand Down Expand Up @@ -940,8 +940,8 @@ public:
constexpr auto _Pocma_val = _Choose_pocma_v<_Alnode>;
if constexpr (_Pocma_val == _Pocma_values::_Propagate_allocators) {
if (_Al != _Right_al) {
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Al);
auto&& _Right_alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Right_al);
auto _Alproxy = _STD _Get_proxy_allocator(_Al);
auto _Right_alproxy = _STD _Get_proxy_allocator(_Right_al);
_Container_proxy_ptr<_Alty> _Proxy(_Right_alproxy, _Leave_proxy_unbound{});
auto& _My_data = _Mypair._Myval2;
auto& _Right_data = _Right._Mypair._Myval2;
Expand Down Expand Up @@ -1060,17 +1060,17 @@ public:
~list() noexcept {
_Tidy();
#if _ITERATOR_DEBUG_LEVEL != 0 // TRANSITION, ABI
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Getal());
auto _Alproxy = _STD _Get_proxy_allocator(_Getal());
_Delete_plain_internal(_Alproxy, _Mypair._Myval2._Myproxy);
#endif // _ITERATOR_DEBUG_LEVEL != 0
}

private:
void _Reload_sentinel_and_proxy(const list& _Right) { // reload sentinel / proxy from unequal POCCA _Right
auto& _Al = _Getal();
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Al);
auto& _Right_al = _Right._Getal();
auto&& _Right_alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Right_al);
auto& _Al = _Getal();
auto _Alproxy = _STD _Get_proxy_allocator(_Al);
auto& _Right_al = _Right._Getal();
auto _Right_alproxy = _STD _Get_proxy_allocator(_Right_al);
_Container_proxy_ptr<_Alty> _Proxy(_Right_alproxy, _Leave_proxy_unbound{});
auto _Right_al_non_const = _Right_al;
auto _Newhead = _Node::_Buyheadnode(_Right_al_non_const);
Expand Down Expand Up @@ -1845,7 +1845,7 @@ private:
}

void _Alloc_sentinel_and_proxy() {
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Getal());
auto _Alproxy = _STD _Get_proxy_allocator(_Getal());
_Container_proxy_ptr<_Alty> _Proxy(_Alproxy, _Mypair._Myval2);
auto& _Al = _Getal();
auto _Newhead = _Al.allocate(1);
Expand Down
42 changes: 21 additions & 21 deletions stl/inc/vector
Original file line number Diff line number Diff line change
Expand Up @@ -668,11 +668,11 @@ public:
using const_reverse_iterator = _STD reverse_iterator<const_iterator>;

_CONSTEXPR20 vector() noexcept(is_nothrow_default_constructible_v<_Alty>) : _Mypair(_Zero_then_variadic_args_t{}) {
_Mypair._Myval2._Alloc_proxy(_GET_PROXY_ALLOCATOR(_Alty, _Getal()));
_Mypair._Myval2._Alloc_proxy(_STD _Get_proxy_allocator(_Getal()));
}

_CONSTEXPR20 explicit vector(const _Alloc& _Al) noexcept : _Mypair(_One_then_variadic_args_t{}, _Al) {
_Mypair._Myval2._Alloc_proxy(_GET_PROXY_ALLOCATOR(_Alty, _Getal()));
_Mypair._Myval2._Alloc_proxy(_STD _Get_proxy_allocator(_Getal()));
}

_CONSTEXPR20 explicit vector(_CRT_GUARDOVERFLOW const size_type _Count, const _Alloc& _Al = _Alloc())
Expand Down Expand Up @@ -705,7 +705,7 @@ public:
_Construct_n(_Count, _STD move(_UFirst), _STD move(_ULast));
#endif // _HAS_CXX20
} else {
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alty, _Getal());
auto _Alproxy = _STD _Get_proxy_allocator(_Getal());
_Container_proxy_ptr<_Alty> _Proxy(_Alproxy, _Mypair._Myval2);
_Tidy_guard<vector> _Guard{this};

Expand All @@ -730,7 +730,7 @@ public:
const auto _Count = _Convert_size<size_type>(_Length);
_Construct_n(_Count, _RANGES _Ubegin(_Range), _RANGES _Uend(_Range));
} else {
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alty, _Getal());
auto _Alproxy = _STD _Get_proxy_allocator(_Getal());
_Container_proxy_ptr<_Alty> _Proxy(_Alproxy, _Mypair._Myval2);
_Tidy_guard<vector> _Guard{this};

Expand Down Expand Up @@ -761,15 +761,15 @@ public:
_STD exchange(_Right._Mypair._Myval2._Myfirst, nullptr),
_STD exchange(_Right._Mypair._Myval2._Mylast, nullptr),
_STD exchange(_Right._Mypair._Myval2._Myend, nullptr)) {
_Mypair._Myval2._Alloc_proxy(_GET_PROXY_ALLOCATOR(_Alty, _Getal()));
_Mypair._Myval2._Alloc_proxy(_STD _Get_proxy_allocator(_Getal()));
_Mypair._Myval2._Swap_proxy_and_iterators(_Right._Mypair._Myval2);
}

_CONSTEXPR20 vector(vector&& _Right, const _Identity_t<_Alloc>& _Al_)
noexcept(_Alty_traits::is_always_equal::value) // strengthened
: _Mypair(_One_then_variadic_args_t{}, _Al_) {
_Alty& _Al = _Getal();
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alty, _Al);
auto _Alproxy = _STD _Get_proxy_allocator(_Al);
auto& _My_data = _Mypair._Myval2;
auto& _Right_data = _Right._Mypair._Myval2;
_Container_proxy_ptr<_Alty> _Proxy(_Alproxy, _My_data);
Expand Down Expand Up @@ -816,7 +816,7 @@ public:
if constexpr (_Pocma_val == _Pocma_values::_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));
_Mypair._Myval2._Reload_proxy(_STD _Get_proxy_allocator(_Al), _STD _Get_proxy_allocator(_Right_al));
}
}
#endif // _ITERATOR_DEBUG_LEVEL != 0
Expand All @@ -829,7 +829,7 @@ public:
_CONSTEXPR20 ~vector() noexcept {
_Tidy();
#if _ITERATOR_DEBUG_LEVEL != 0
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alty, _Getal());
auto _Alproxy = _STD _Get_proxy_allocator(_Getal());
_Delete_plain_internal(_Alproxy, _STD exchange(_Mypair._Myval2._Myproxy, nullptr));
#endif // _ITERATOR_DEBUG_LEVEL != 0
}
Expand Down Expand Up @@ -1530,7 +1530,7 @@ public:
if constexpr (_Choose_pocca_v<_Alty>) {
if (_Al != _Right_al) {
_Tidy();
_Mypair._Myval2._Reload_proxy(_GET_PROXY_ALLOCATOR(_Alty, _Al), _GET_PROXY_ALLOCATOR(_Alty, _Right_al));
_Mypair._Myval2._Reload_proxy(_STD _Get_proxy_allocator(_Al), _STD _Get_proxy_allocator(_Right_al));
}
}

Expand Down Expand Up @@ -2104,9 +2104,9 @@ private:
// 1-arg -> value-construction, e.g. vector(5)
// 2-arg -> fill, e.g. vector(5, "meow")
// 3-arg -> sized range construction, e.g. vector{"Hello", "Fluffy", "World"}
auto& _Al = _Getal();
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alty, _Al);
auto& _My_data = _Mypair._Myval2;
auto& _Al = _Getal();
auto _Alproxy = _STD _Get_proxy_allocator(_Al);
auto& _My_data = _Mypair._Myval2;
_Container_proxy_ptr<_Alty> _Proxy(_Alproxy, _My_data);
if (_Count != 0) {
_Buy_nonzero(_Count);
Expand Down Expand Up @@ -2816,35 +2816,35 @@ public:
using size_type = typename _Alvbase_traits::size_type;

_CONSTEXPR20 _Vb_val() noexcept(is_nothrow_default_constructible_v<_Vectype>) : _Myvec(), _Mysize(0) {
this->_Alloc_proxy(_GET_PROXY_ALLOCATOR(_Alvbase, _Getal()));
this->_Alloc_proxy(_STD _Get_proxy_allocator(_Getal()));
}

_CONSTEXPR20 _Vb_val(const _Alloc& _Al) noexcept : _Myvec(static_cast<_Alvbase>(_Al)), _Mysize(0) {
this->_Alloc_proxy(_GET_PROXY_ALLOCATOR(_Alvbase, _Getal()));
this->_Alloc_proxy(_STD _Get_proxy_allocator(_Getal()));
}

_CONSTEXPR20 _Vb_val(size_type _Count, const bool& _Val)
: _Myvec(_Nw(_Count), static_cast<_Vbase>(_Val ? -1 : 0)), _Mysize(0) {
this->_Alloc_proxy(_GET_PROXY_ALLOCATOR(_Alvbase, _Getal()));
this->_Alloc_proxy(_STD _Get_proxy_allocator(_Getal()));
}

_CONSTEXPR20 _Vb_val(size_type _Count, const bool& _Val, const _Alloc& _Al)
: _Myvec(_Nw(_Count), static_cast<_Vbase>(_Val ? -1 : 0), static_cast<_Alvbase>(_Al)), _Mysize(0) {
this->_Alloc_proxy(_GET_PROXY_ALLOCATOR(_Alvbase, _Getal()));
this->_Alloc_proxy(_STD _Get_proxy_allocator(_Getal()));
}

_CONSTEXPR20 _Vb_val(const _Vb_val& _Right) : _Myvec(_Right._Myvec), _Mysize(_Right._Mysize) {
this->_Alloc_proxy(_GET_PROXY_ALLOCATOR(_Alvbase, _Getal()));
this->_Alloc_proxy(_STD _Get_proxy_allocator(_Getal()));
}

_CONSTEXPR20 _Vb_val(const _Vb_val& _Right, const _Alloc& _Al)
: _Myvec(_Right._Myvec, static_cast<_Alvbase>(_Al)), _Mysize(_Right._Mysize) {
this->_Alloc_proxy(_GET_PROXY_ALLOCATOR(_Alvbase, _Getal()));
this->_Alloc_proxy(_STD _Get_proxy_allocator(_Getal()));
}

_CONSTEXPR20 _Vb_val(_Vb_val&& _Right) noexcept(is_nothrow_move_constructible_v<_Vectype>)
: _Myvec(_STD move(_Right._Myvec)), _Mysize(_STD exchange(_Right._Mysize, size_type{0})) {
this->_Alloc_proxy(_GET_PROXY_ALLOCATOR(_Alvbase, _Getal()));
this->_Alloc_proxy(_STD _Get_proxy_allocator(_Getal()));
}

_CONSTEXPR20 _Vb_val(_Vb_val&& _Right, const _Alloc& _Al)
Expand All @@ -2855,13 +2855,13 @@ public:
_Right._Mysize = 0;
}

this->_Alloc_proxy(_GET_PROXY_ALLOCATOR(_Alvbase, _Getal()));
this->_Alloc_proxy(_STD _Get_proxy_allocator(_Getal()));
}

_CONSTEXPR20 ~_Vb_val() noexcept {
#if _ITERATOR_DEBUG_LEVEL != 0
this->_Orphan_all();
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alvbase, this->_Getal());
auto _Alproxy = _STD _Get_proxy_allocator(this->_Getal());
_Delete_plain_internal(_Alproxy, _STD exchange(this->_Myproxy, nullptr));
#endif // _ITERATOR_DEBUG_LEVEL != 0

Expand Down
14 changes: 7 additions & 7 deletions stl/inc/xhash
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,13 @@ struct _Hash_vec {
_Vec_iter_types<value_type, size_type, difference_type, pointer, typename _Aliter_traits::const_pointer>>>;

_Hash_vec() : _Mypair(_Zero_then_variadic_args_t{}) {
_Mypair._Myval2._Alloc_proxy(_GET_PROXY_ALLOCATOR(_Aliter, _Mypair._Get_first()));
_Mypair._Myval2._Alloc_proxy(_STD _Get_proxy_allocator(_Mypair._Get_first()));
}

template <class _Any_alloc, enable_if_t<!is_same_v<_Remove_cvref_t<_Any_alloc>, _Hash_vec>, int> = 0>
explicit _Hash_vec(_Any_alloc&& _Al) noexcept
: _Mypair(_One_then_variadic_args_t{}, _STD forward<_Any_alloc>(_Al)) { // construct empty vector, allocator
_Mypair._Myval2._Alloc_proxy(_GET_PROXY_ALLOCATOR(_Aliter, _Mypair._Get_first()));
_Mypair._Myval2._Alloc_proxy(_STD _Get_proxy_allocator(_Mypair._Get_first()));
}

_Hash_vec(const _Hash_vec&) = delete;
Expand Down Expand Up @@ -316,7 +316,7 @@ struct _Hash_vec {
~_Hash_vec() {
_Tidy();
#if _ITERATOR_DEBUG_LEVEL != 0
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Aliter, _Mypair._Get_first());
auto _Alproxy = _STD _Get_proxy_allocator(_Mypair._Get_first());
_Delete_plain_internal(_Alproxy, _STD exchange(_Mypair._Myval2._Myproxy, nullptr));
#endif // _ITERATOR_DEBUG_LEVEL != 0
}
Expand Down Expand Up @@ -523,8 +523,8 @@ public:
if constexpr (_Pocma_val == _Pocma_values::_Propagate_allocators) {
if (_Al != _Right_al) {
// allocate all the parts necessary to maintain _Hash invariants using _Right's allocator
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Al);
auto&& _Right_alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Right_al);
auto _Alproxy = _STD _Get_proxy_allocator(_Al);
auto _Right_alproxy = _STD _Get_proxy_allocator(_Right_al);
_Container_proxy_ptr<_Alnode> _List_proxy(_Right_alproxy, _Leave_proxy_unbound{});
_Container_proxy_ptr<_Alnode> _Vec_proxy(_Right_alproxy, _Leave_proxy_unbound{});
_List_head_construct_ptr<_Alnode> _Newhead(_Right_al);
Expand Down Expand Up @@ -758,8 +758,8 @@ public:
auto& _Al = _Getal();
const auto& _Right_al = _Right._Getal();
if (_Al != _Right_al) {
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Al);
auto&& _Right_alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Right_al);
auto _Alproxy = _STD _Get_proxy_allocator(_Al);
auto _Right_alproxy = _STD _Get_proxy_allocator(_Right_al);
_Container_proxy_ptr<_Alnode> _Vec_proxy(_Right_alproxy, _Leave_proxy_unbound{});
_List._Reload_sentinel_and_proxy(_Right._List);
_Vec._Tidy();
Expand Down
14 changes: 11 additions & 3 deletions stl/inc/xmemory
Original file line number Diff line number Diff line change
Expand Up @@ -1504,12 +1504,20 @@ struct _Container_proxy_ptr12 : _Basic_container_proxy_ptr12 {
};

#if _ITERATOR_DEBUG_LEVEL == 0
#define _GET_PROXY_ALLOCATOR(_Alty, _Al) \
_Fake_allocator {}
template <class _Alloc>
_CONSTEXPR20 _Fake_allocator _Get_proxy_allocator(const _Alloc&) noexcept {
return {};
}

template <class _Alloc>
using _Container_proxy_ptr = _Fake_proxy_ptr_impl;
#else // ^^^ _ITERATOR_DEBUG_LEVEL == 0 / _ITERATOR_DEBUG_LEVEL > 0 vvv
#define _GET_PROXY_ALLOCATOR(_Alty, _Al) static_cast<_Rebind_alloc_t<_Alty, _Container_proxy>>(_Al)
template <class _Alloc>
_CONSTEXPR20 _Rebind_alloc_t<_Alloc, _Container_proxy> _Get_proxy_allocator(const _Alloc& _Al)
noexcept(noexcept(static_cast<_Rebind_alloc_t<_Alloc, _Container_proxy>>(_Al))) {
return static_cast<_Rebind_alloc_t<_Alloc, _Container_proxy>>(_Al);
}

template <class _Alloc>
using _Container_proxy_ptr = _Container_proxy_ptr12<_Rebind_alloc_t<_Alloc, _Container_proxy>>;
#endif // ^^^ _ITERATOR_DEBUG_LEVEL > 0 ^^^
Expand Down
Loading