Skip to content

Commit b11194b

Browse files
Replace _GET_PROXY_ALLOCATOR with a function template
1 parent 8e9f4ee commit b11194b

File tree

7 files changed

+81
-74
lines changed

7 files changed

+81
-74
lines changed

stl/inc/forward_list

+5-6
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ public:
675675
if (_Al != _Right_al) {
676676
_Mypair._Myval2._Orphan_all();
677677
clear();
678-
_Mypair._Myval2._Reload_proxy(_GET_PROXY_ALLOCATOR(_Alty, _Al), _GET_PROXY_ALLOCATOR(_Alty, _Right_al));
678+
_Mypair._Myval2._Reload_proxy(_STD _Get_proxy_allocator(_Al), _Get_proxy_allocator(_Right_al));
679679
_Pocma(_Al, _Right_al);
680680
_Take_head(_Right);
681681
return *this;
@@ -741,7 +741,7 @@ private:
741741
public:
742742
forward_list(initializer_list<_Ty> _Ilist, const _Alloc& _Al = allocator_type())
743743
: _Mypair(_One_then_variadic_args_t{}, _Al) {
744-
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Getal());
744+
auto _Alproxy = _STD _Get_proxy_allocator(_Getal());
745745
_Container_proxy_ptr<_Alty> _Proxy(_Alproxy, _Mypair._Myval2);
746746
insert_after(before_begin(), _Ilist.begin(), _Ilist.end());
747747
_Proxy._Release();
@@ -764,7 +764,7 @@ public:
764764
~forward_list() noexcept {
765765
clear();
766766
#if _ITERATOR_DEBUG_LEVEL != 0 // TRANSITION, ABI
767-
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alty, _Getal());
767+
auto _Alproxy = _STD _Get_proxy_allocator(_Getal());
768768
_Delete_plain_internal(_Alproxy, _Mypair._Myval2._Myproxy);
769769
#endif // _ITERATOR_DEBUG_LEVEL != 0
770770
}
@@ -780,8 +780,7 @@ public:
780780
if (_Al != _Right_al) {
781781
_Mypair._Myval2._Orphan_all();
782782
clear();
783-
_Mypair._Myval2._Reload_proxy(
784-
_GET_PROXY_ALLOCATOR(_Alnode, _Al), _GET_PROXY_ALLOCATOR(_Alnode, _Right_al));
783+
_Mypair._Myval2._Reload_proxy(_STD _Get_proxy_allocator(_Al), _STD _Get_proxy_allocator(_Right_al));
785784
}
786785
}
787786

@@ -1551,7 +1550,7 @@ private:
15511550
}
15521551

15531552
void _Alloc_proxy() {
1554-
_Mypair._Myval2._Alloc_proxy(_GET_PROXY_ALLOCATOR(_Alnode, _Getal()));
1553+
_Mypair._Myval2._Alloc_proxy(_STD _Get_proxy_allocator(_Getal()));
15551554
}
15561555

15571556
void _Swap_proxy_and_iterators(forward_list& _Right) noexcept {

stl/inc/list

+11-11
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ private:
824824
}
825825

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

846846
private:
847847
void _Construct_n(_CRT_GUARDOVERFLOW size_type _Count, const _Ty& _Val) {
848-
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Getal());
848+
auto _Alproxy = _STD _Get_proxy_allocator(_Getal());
849849
_Container_proxy_ptr<_Alty> _Proxy(_Alproxy, _Mypair._Myval2);
850850
_List_node_insert_op2<_Alnode> _Appended(_Getal());
851851
_Appended._Append_n(_Count, _Val);
@@ -870,7 +870,7 @@ public:
870870
private:
871871
template <class _Iter, class _Sent>
872872
void _Construct_range_unchecked(_Iter _First, const _Sent _Last) {
873-
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Getal());
873+
auto _Alproxy = _STD _Get_proxy_allocator(_Getal());
874874
_Container_proxy_ptr<_Alty> _Proxy(_Alproxy, _Mypair._Myval2);
875875
_List_node_insert_op2<_Alnode> _Appended(_Getal());
876876
_Appended._Append_range_unchecked(_STD move(_First), _Last);
@@ -940,8 +940,8 @@ public:
940940
constexpr auto _Pocma_val = _Choose_pocma_v<_Alnode>;
941941
if constexpr (_Pocma_val == _Pocma_values::_Propagate_allocators) {
942942
if (_Al != _Right_al) {
943-
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Al);
944-
auto&& _Right_alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Right_al);
943+
auto _Alproxy = _STD _Get_proxy_allocator(_Al);
944+
auto _Right_alproxy = _STD _Get_proxy_allocator(_Right_al);
945945
_Container_proxy_ptr<_Alty> _Proxy(_Right_alproxy, _Leave_proxy_unbound{});
946946
auto& _My_data = _Mypair._Myval2;
947947
auto& _Right_data = _Right._Mypair._Myval2;
@@ -1060,17 +1060,17 @@ public:
10601060
~list() noexcept {
10611061
_Tidy();
10621062
#if _ITERATOR_DEBUG_LEVEL != 0 // TRANSITION, ABI
1063-
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Getal());
1063+
auto _Alproxy = _STD _Get_proxy_allocator(_Getal());
10641064
_Delete_plain_internal(_Alproxy, _Mypair._Myval2._Myproxy);
10651065
#endif // _ITERATOR_DEBUG_LEVEL != 0
10661066
}
10671067

10681068
private:
10691069
void _Reload_sentinel_and_proxy(const list& _Right) { // reload sentinel / proxy from unequal POCCA _Right
1070-
auto& _Al = _Getal();
1071-
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Al);
1072-
auto& _Right_al = _Right._Getal();
1073-
auto&& _Right_alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Right_al);
1070+
auto& _Al = _Getal();
1071+
auto _Alproxy = _STD _Get_proxy_allocator(_Al);
1072+
auto& _Right_al = _Right._Getal();
1073+
auto _Right_alproxy = _STD _Get_proxy_allocator(_Right_al);
10741074
_Container_proxy_ptr<_Alty> _Proxy(_Right_alproxy, _Leave_proxy_unbound{});
10751075
auto _Right_al_non_const = _Right_al;
10761076
auto _Newhead = _Node::_Buyheadnode(_Right_al_non_const);
@@ -1845,7 +1845,7 @@ private:
18451845
}
18461846

18471847
void _Alloc_sentinel_and_proxy() {
1848-
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Getal());
1848+
auto _Alproxy = _STD _Get_proxy_allocator(_Getal());
18491849
_Container_proxy_ptr<_Alty> _Proxy(_Alproxy, _Mypair._Myval2);
18501850
auto& _Al = _Getal();
18511851
auto _Newhead = _Al.allocate(1);

stl/inc/vector

+21-21
Original file line numberDiff line numberDiff line change
@@ -668,11 +668,11 @@ public:
668668
using const_reverse_iterator = _STD reverse_iterator<const_iterator>;
669669

670670
_CONSTEXPR20 vector() noexcept(is_nothrow_default_constructible_v<_Alty>) : _Mypair(_Zero_then_variadic_args_t{}) {
671-
_Mypair._Myval2._Alloc_proxy(_GET_PROXY_ALLOCATOR(_Alty, _Getal()));
671+
_Mypair._Myval2._Alloc_proxy(_STD _Get_proxy_allocator(_Getal()));
672672
}
673673

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

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

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

@@ -761,15 +761,15 @@ public:
761761
_STD exchange(_Right._Mypair._Myval2._Myfirst, nullptr),
762762
_STD exchange(_Right._Mypair._Myval2._Mylast, nullptr),
763763
_STD exchange(_Right._Mypair._Myval2._Myend, nullptr)) {
764-
_Mypair._Myval2._Alloc_proxy(_GET_PROXY_ALLOCATOR(_Alty, _Getal()));
764+
_Mypair._Myval2._Alloc_proxy(_STD _Get_proxy_allocator(_Getal()));
765765
_Mypair._Myval2._Swap_proxy_and_iterators(_Right._Mypair._Myval2);
766766
}
767767

768768
_CONSTEXPR20 vector(vector&& _Right, const _Identity_t<_Alloc>& _Al_)
769769
noexcept(_Alty_traits::is_always_equal::value) // strengthened
770770
: _Mypair(_One_then_variadic_args_t{}, _Al_) {
771771
_Alty& _Al = _Getal();
772-
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alty, _Al);
772+
auto _Alproxy = _STD _Get_proxy_allocator(_Al);
773773
auto& _My_data = _Mypair._Myval2;
774774
auto& _Right_data = _Right._Mypair._Myval2;
775775
_Container_proxy_ptr<_Alty> _Proxy(_Alproxy, _My_data);
@@ -816,7 +816,7 @@ public:
816816
if constexpr (_Pocma_val == _Pocma_values::_Propagate_allocators) {
817817
if (_Al != _Right_al) {
818818
// intentionally slams into noexcept on OOM, TRANSITION, VSO-466800
819-
_Mypair._Myval2._Reload_proxy(_GET_PROXY_ALLOCATOR(_Alty, _Al), _GET_PROXY_ALLOCATOR(_Alty, _Right_al));
819+
_Mypair._Myval2._Reload_proxy(_STD _Get_proxy_allocator(_Al), _STD _Get_proxy_allocator(_Right_al));
820820
}
821821
}
822822
#endif // _ITERATOR_DEBUG_LEVEL != 0
@@ -829,7 +829,7 @@ public:
829829
_CONSTEXPR20 ~vector() noexcept {
830830
_Tidy();
831831
#if _ITERATOR_DEBUG_LEVEL != 0
832-
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alty, _Getal());
832+
auto _Alproxy = _STD _Get_proxy_allocator(_Getal());
833833
_Delete_plain_internal(_Alproxy, _STD exchange(_Mypair._Myval2._Myproxy, nullptr));
834834
#endif // _ITERATOR_DEBUG_LEVEL != 0
835835
}
@@ -1530,7 +1530,7 @@ public:
15301530
if constexpr (_Choose_pocca_v<_Alty>) {
15311531
if (_Al != _Right_al) {
15321532
_Tidy();
1533-
_Mypair._Myval2._Reload_proxy(_GET_PROXY_ALLOCATOR(_Alty, _Al), _GET_PROXY_ALLOCATOR(_Alty, _Right_al));
1533+
_Mypair._Myval2._Reload_proxy(_STD _Get_proxy_allocator(_Al), _STD _Get_proxy_allocator(_Right_al));
15341534
}
15351535
}
15361536

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

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

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

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

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

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

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

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

28502850
_CONSTEXPR20 _Vb_val(_Vb_val&& _Right, const _Alloc& _Al)
@@ -2855,13 +2855,13 @@ public:
28552855
_Right._Mysize = 0;
28562856
}
28572857

2858-
this->_Alloc_proxy(_GET_PROXY_ALLOCATOR(_Alvbase, _Getal()));
2858+
this->_Alloc_proxy(_STD _Get_proxy_allocator(_Getal()));
28592859
}
28602860

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

stl/inc/xhash

+7-7
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,13 @@ struct _Hash_vec {
252252
_Vec_iter_types<value_type, size_type, difference_type, pointer, typename _Aliter_traits::const_pointer>>>;
253253

254254
_Hash_vec() : _Mypair(_Zero_then_variadic_args_t{}) {
255-
_Mypair._Myval2._Alloc_proxy(_GET_PROXY_ALLOCATOR(_Aliter, _Mypair._Get_first()));
255+
_Mypair._Myval2._Alloc_proxy(_STD _Get_proxy_allocator(_Mypair._Get_first()));
256256
}
257257

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

264264
_Hash_vec(const _Hash_vec&) = delete;
@@ -316,7 +316,7 @@ struct _Hash_vec {
316316
~_Hash_vec() {
317317
_Tidy();
318318
#if _ITERATOR_DEBUG_LEVEL != 0
319-
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Aliter, _Mypair._Get_first());
319+
auto _Alproxy = _STD _Get_proxy_allocator(_Mypair._Get_first());
320320
_Delete_plain_internal(_Alproxy, _STD exchange(_Mypair._Myval2._Myproxy, nullptr));
321321
#endif // _ITERATOR_DEBUG_LEVEL != 0
322322
}
@@ -523,8 +523,8 @@ public:
523523
if constexpr (_Pocma_val == _Pocma_values::_Propagate_allocators) {
524524
if (_Al != _Right_al) {
525525
// allocate all the parts necessary to maintain _Hash invariants using _Right's allocator
526-
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Al);
527-
auto&& _Right_alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Right_al);
526+
auto _Alproxy = _STD _Get_proxy_allocator(_Al);
527+
auto _Right_alproxy = _STD _Get_proxy_allocator(_Right_al);
528528
_Container_proxy_ptr<_Alnode> _List_proxy(_Right_alproxy, _Leave_proxy_unbound{});
529529
_Container_proxy_ptr<_Alnode> _Vec_proxy(_Right_alproxy, _Leave_proxy_unbound{});
530530
_List_head_construct_ptr<_Alnode> _Newhead(_Right_al);
@@ -758,8 +758,8 @@ public:
758758
auto& _Al = _Getal();
759759
const auto& _Right_al = _Right._Getal();
760760
if (_Al != _Right_al) {
761-
auto&& _Alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Al);
762-
auto&& _Right_alproxy = _GET_PROXY_ALLOCATOR(_Alnode, _Right_al);
761+
auto _Alproxy = _STD _Get_proxy_allocator(_Al);
762+
auto _Right_alproxy = _STD _Get_proxy_allocator(_Right_al);
763763
_Container_proxy_ptr<_Alnode> _Vec_proxy(_Right_alproxy, _Leave_proxy_unbound{});
764764
_List._Reload_sentinel_and_proxy(_Right._List);
765765
_Vec._Tidy();

stl/inc/xmemory

+11-3
Original file line numberDiff line numberDiff line change
@@ -1504,12 +1504,20 @@ struct _Container_proxy_ptr12 : _Basic_container_proxy_ptr12 {
15041504
};
15051505

15061506
#if _ITERATOR_DEBUG_LEVEL == 0
1507-
#define _GET_PROXY_ALLOCATOR(_Alty, _Al) \
1508-
_Fake_allocator {}
1507+
template <class _Alloc>
1508+
_CONSTEXPR20 _Fake_allocator _Get_proxy_allocator(const _Alloc&) noexcept {
1509+
return {};
1510+
}
1511+
15091512
template <class _Alloc>
15101513
using _Container_proxy_ptr = _Fake_proxy_ptr_impl;
15111514
#else // ^^^ _ITERATOR_DEBUG_LEVEL == 0 / _ITERATOR_DEBUG_LEVEL > 0 vvv
1512-
#define _GET_PROXY_ALLOCATOR(_Alty, _Al) static_cast<_Rebind_alloc_t<_Alty, _Container_proxy>>(_Al)
1515+
template <class _Alloc>
1516+
_CONSTEXPR20 _Rebind_alloc_t<_Alloc, _Container_proxy> _Get_proxy_allocator(const _Alloc& _Al)
1517+
noexcept(noexcept(static_cast<Rebind_alloc_t<_Alloc, _Container_proxy>>(_Al))) {
1518+
return static_cast<Rebind_alloc_t<_Alloc, _Container_proxy>>(_Al);
1519+
}
1520+
15131521
template <class _Alloc>
15141522
using _Container_proxy_ptr = _Container_proxy_ptr12<_Rebind_alloc_t<_Alloc, _Container_proxy>>;
15151523
#endif // ^^^ _ITERATOR_DEBUG_LEVEL > 0 ^^^

0 commit comments

Comments
 (0)