From d46c27f648002183b269ea8c0194ee2bfd73b9bf Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Fri, 27 Aug 2021 07:01:38 +0700 Subject: [PATCH] P1518R2 Stop Overconstraining Allocators In Container Deduction Guides (#2032) Co-authored-by: Michael Schellenberger Costa Co-authored-by: Stephan T. Lavavej --- stl/inc/deque | 4 +- stl/inc/forward_list | 5 +- stl/inc/list | 4 +- stl/inc/queue | 8 +- stl/inc/stack | 4 +- stl/inc/vector | 9 +- stl/inc/yvals_core.h | 1 + tests/std/test.lst | 1 + .../env.lst | 4 + .../test.compile.pass.cpp | 137 ++++++++++++++++++ 10 files changed, 159 insertions(+), 18 deletions(-) create mode 100644 tests/std/tests/P1518R2_stop_overconstraining_allocators/env.lst create mode 100644 tests/std/tests/P1518R2_stop_overconstraining_allocators/test.compile.pass.cpp diff --git a/stl/inc/deque b/stl/inc/deque index 89a22445cf..c605cd56de 100644 --- a/stl/inc/deque +++ b/stl/inc/deque @@ -657,7 +657,7 @@ public: _Proxy._Release(); } - deque(const deque& _Right, const _Alloc& _Al) : _Mypair(_One_then_variadic_args_t{}, _Al) { + deque(const deque& _Right, const _Identity_t<_Alloc>& _Al) : _Mypair(_One_then_variadic_args_t{}, _Al) { _Alproxy_ty _Alproxy(_Getal()); _Container_proxy_ptr12<_Alproxy_ty> _Proxy(_Alproxy, _Get_data()); _Construct(_Right._Unchecked_begin(), _Right._Unchecked_end()); @@ -706,7 +706,7 @@ public: _Take_contents(_Right); } - deque(deque&& _Right, const _Alloc& _Al) : _Mypair(_One_then_variadic_args_t{}, _Al) { + deque(deque&& _Right, const _Identity_t<_Alloc>& _Al) : _Mypair(_One_then_variadic_args_t{}, _Al) { _Alproxy_ty _Alproxy(_Getal()); if constexpr (!_Alty_traits::is_always_equal::value) { if (_Getal() != _Right._Getal()) { diff --git a/stl/inc/forward_list b/stl/inc/forward_list index 1049739bc1..a26a34c93b 100644 --- a/stl/inc/forward_list +++ b/stl/inc/forward_list @@ -580,7 +580,8 @@ public: _Insert_op._Attach_after(_Mypair._Myval2._Before_head()); } - forward_list(const forward_list& _Right, const _Alloc& _Al) : _Mypair(_One_then_variadic_args_t{}, _Al) { + forward_list(const forward_list& _Right, const _Identity_t<_Alloc>& _Al) + : _Mypair(_One_then_variadic_args_t{}, _Al) { _Flist_insert_after_op2<_Alnode> _Insert_op(_Getal()); _Insert_op._Append_range_unchecked(_Right._Unchecked_begin(), _Right._Unchecked_end()); _Alloc_proxy(); @@ -611,7 +612,7 @@ public: _Take_head(_Right); } - forward_list(forward_list&& _Right, const _Alloc& _Al) noexcept( + forward_list(forward_list&& _Right, const _Identity_t<_Alloc>& _Al) noexcept( _Alnode_traits::is_always_equal::value) // strengthened : _Mypair(_One_then_variadic_args_t{}, _Al) { if constexpr (!_Alty_traits::is_always_equal::value) { diff --git a/stl/inc/list b/stl/inc/list index 3c698fe404..f4548c4340 100644 --- a/stl/inc/list +++ b/stl/inc/list @@ -864,7 +864,7 @@ public: _Construct_range_unchecked(_Right._Unchecked_begin(), _Right._Unchecked_end()); } - list(const list& _Right, const _Alloc& _Al) : _Mypair(_One_then_variadic_args_t{}, _Al) { + list(const list& _Right, const _Identity_t<_Alloc>& _Al) : _Mypair(_One_then_variadic_args_t{}, _Al) { _Construct_range_unchecked(_Right._Unchecked_begin(), _Right._Unchecked_end()); } @@ -885,7 +885,7 @@ public: _Swap_val(_Right); } - list(list&& _Right, const _Alloc& _Al) : _Mypair(_One_then_variadic_args_t{}, _Al) { + list(list&& _Right, const _Identity_t<_Alloc>& _Al) : _Mypair(_One_then_variadic_args_t{}, _Al) { if constexpr (!_Alnode_traits::is_always_equal::value) { if (_Getal() != _Right._Getal()) { _Construct_range_unchecked(_STD make_move_iterator(_Right._Unchecked_begin()), diff --git a/stl/inc/queue b/stl/inc/queue index e0583c98db..d798d5ed4f 100644 --- a/stl/inc/queue +++ b/stl/inc/queue @@ -134,9 +134,7 @@ template ::value, int> queue(_Container) -> queue; template >, _Is_allocator<_Alloc>, uses_allocator<_Container, _Alloc>>, - int> = 0> + enable_if_t>, uses_allocator<_Container, _Alloc>>, int> = 0> queue(_Container, _Alloc) -> queue; #endif // _HAS_CXX17 @@ -354,7 +352,7 @@ priority_queue(_Iter, _Iter, _Pr = _Pr(), _Container = _Container()) -> priority_queue<_Iter_value_t<_Iter>, _Container, _Pr>; template >, negation<_Is_allocator<_Container>>, _Is_allocator<_Alloc>, + enable_if_t>, negation<_Is_allocator<_Container>>, uses_allocator<_Container, _Alloc>>, int> = 0> priority_queue(_Pr, _Container, _Alloc) -> priority_queue; @@ -368,7 +366,7 @@ template priority_queue<_Iter_value_t<_Iter>, _Container, _Compare>; template , _Is_allocator<_Alloc>, uses_allocator<_Container, _Alloc>>, int> = 0> + enable_if_t, uses_allocator<_Container, _Alloc>>, int> = 0> priority_queue(_Iter, _Iter, _Compare, _Container, _Alloc) -> priority_queue; #endif // _HAS_CXX17 diff --git a/stl/inc/stack b/stl/inc/stack index 6a4a5e9f9b..6364392161 100644 --- a/stl/inc/stack +++ b/stl/inc/stack @@ -124,9 +124,7 @@ template ::value, int> stack(_Container) -> stack; template >, _Is_allocator<_Alloc>, uses_allocator<_Container, _Alloc>>, - int> = 0> + enable_if_t>, uses_allocator<_Container, _Alloc>>, int> = 0> stack(_Container, _Alloc) -> stack; #endif // _HAS_CXX17 diff --git a/stl/inc/vector b/stl/inc/vector index 503a506f83..6c966541cb 100644 --- a/stl/inc/vector +++ b/stl/inc/vector @@ -520,7 +520,8 @@ public: _Construct_n(_Count, _Right_data._Myfirst, _Right_data._Mylast); } - _CONSTEXPR20 vector(const vector& _Right, const _Alloc& _Al) : _Mypair(_One_then_variadic_args_t{}, _Al) { + _CONSTEXPR20 vector(const vector& _Right, const _Identity_t<_Alloc>& _Al) + : _Mypair(_One_then_variadic_args_t{}, _Al) { const auto& _Right_data = _Right._Mypair._Myval2; const auto _Count = static_cast(_Right_data._Mylast - _Right_data._Myfirst); _Construct_n(_Count, _Right_data._Myfirst, _Right_data._Mylast); @@ -535,7 +536,7 @@ public: _Mypair._Myval2._Swap_proxy_and_iterators(_Right._Mypair._Myval2); } - _CONSTEXPR20 vector(vector&& _Right, const _Alloc& _Al_) noexcept( + _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(); @@ -2472,7 +2473,7 @@ public: _CONSTEXPR20 vector(const vector& _Right) : _Mybase(_Right) {} - _CONSTEXPR20 vector(const vector& _Right, const _Alloc& _Al) : _Mybase(_Right, _Al) {} + _CONSTEXPR20 vector(const vector& _Right, const _Identity_t<_Alloc>& _Al) : _Mybase(_Right, _Al) {} template , int> = 0> _CONSTEXPR20 vector(_Iter _First, _Iter _Last, const _Alloc& _Al = _Alloc()) : _Mybase(_Al) { @@ -2489,7 +2490,7 @@ public: this->_Swap_proxy_and_iterators(_Right); } - _CONSTEXPR20 vector(vector&& _Right, const _Alloc& _Al) noexcept( + _CONSTEXPR20 vector(vector&& _Right, const _Identity_t<_Alloc>& _Al) noexcept( is_nothrow_constructible_v<_Mybase, _Mybase, const _Alloc&>) : _Mybase(_STD move(_Right), _Al) { if constexpr (!_Alvbase_traits::is_always_equal::value) { diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index 531da87699..e9ba8074f7 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -111,6 +111,7 @@ // P0858R0 Constexpr Iterator Requirements // P1065R2 constexpr INVOKE // (the std::invoke function only; other components like bind and reference_wrapper are C++20 only) +// P1518R2 Stop Overconstraining Allocators In Container Deduction Guides // P2162R2 Inheriting From variant // _HAS_CXX17 indirectly controls: diff --git a/tests/std/test.lst b/tests/std/test.lst index 3cac8635ee..91232e42e7 100644 --- a/tests/std/test.lst +++ b/tests/std/test.lst @@ -426,6 +426,7 @@ tests\P1208R6_source_location tests\P1423R3_char8_t_remediation tests\P1425R4_queue_stack_constructors tests\P1502R1_standard_library_header_units +tests\P1518R2_stop_overconstraining_allocators tests\P1614R2_spaceship tests\P1645R1_constexpr_numeric tests\P1682R3_to_underlying diff --git a/tests/std/tests/P1518R2_stop_overconstraining_allocators/env.lst b/tests/std/tests/P1518R2_stop_overconstraining_allocators/env.lst new file mode 100644 index 0000000000..2de7aab295 --- /dev/null +++ b/tests/std/tests/P1518R2_stop_overconstraining_allocators/env.lst @@ -0,0 +1,4 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +RUNALL_INCLUDE ..\usual_17_matrix.lst diff --git a/tests/std/tests/P1518R2_stop_overconstraining_allocators/test.compile.pass.cpp b/tests/std/tests/P1518R2_stop_overconstraining_allocators/test.compile.pass.cpp new file mode 100644 index 0000000000..80b8213462 --- /dev/null +++ b/tests/std/tests/P1518R2_stop_overconstraining_allocators/test.compile.pass.cpp @@ -0,0 +1,137 @@ +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +pmr::monotonic_buffer_resource mr; + +template