From 5ff23362011e39feb64a7d4c7433daede1cd9a3f Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Thu, 1 Jul 2021 08:54:44 +0700 Subject: [PATCH 01/12] trying to implement P1518R2 --- stl/inc/deque | 16 ++- stl/inc/forward_list | 16 ++- stl/inc/list | 16 ++- stl/inc/queue | 6 +- stl/inc/stack | 4 +- stl/inc/vector | 34 +++++- stl/inc/yvals_core.h | 1 + tests/std/test.lst | 1 + .../env.lst | 4 + .../test.compile.pass.cpp | 107 ++++++++++++++++++ 10 files changed, 184 insertions(+), 21 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 9018290d9c6..5cca463f5a8 100644 --- a/stl/inc/deque +++ b/stl/inc/deque @@ -11,6 +11,7 @@ #include #if _HAS_CXX17 +#include #include #endif // _HAS_CXX17 @@ -651,8 +652,12 @@ public: _Construct(_Right._Unchecked_begin(), _Right._Unchecked_end()); _Proxy._Release(); } - - deque(const deque& _Right, const _Alloc& _Al) : _Mypair(_One_then_variadic_args_t{}, _Al) { +#if _HAS_CXX17 + deque(const deque& _Right, const _Identity_t<_Alloc>& _Al) +#else + deque(const deque& _Right, _Alloc& _Al) +#endif // _HAS_CXX17 + : _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()); @@ -700,8 +705,13 @@ public: _Get_data()._Alloc_proxy(static_cast<_Alproxy_ty>(_Getal())); _Take_contents(_Right); } +#if _HAS_CXX17 + deque(deque&& _Right, const _Identity_t<_Alloc>& _Al) +#else + deque(deque&& _Right, const _Alloc& _Al) +#endif // _HAS_CXX17 - deque(deque&& _Right, const _Alloc& _Al) : _Mypair(_One_then_variadic_args_t{}, _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 6505741e507..a5808b4ef9c 100644 --- a/stl/inc/forward_list +++ b/stl/inc/forward_list @@ -11,6 +11,7 @@ #include #if _HAS_CXX17 +#include #include #endif // _HAS_CXX17 @@ -586,8 +587,13 @@ public: _Alloc_proxy(); _Insert_op._Attach_after(_Mypair._Myval2._Before_head()); } +#if _HAS_CXX17 + forward_list(const forward_list& _Right, const _Identity_t<_Alloc>& _Al) +#else + forward_list(const forward_list& _Right, const _Alloc& _Al) +#endif // _HAS_CXX17 - forward_list(const forward_list& _Right, const _Alloc& _Al) : _Mypair(_One_then_variadic_args_t{}, _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(); @@ -618,8 +624,12 @@ public: _Take_head(_Right); } - forward_list(forward_list&& _Right, const _Alloc& _Al) noexcept( - _Alnode_traits::is_always_equal::value) // strengthened +#if _HAS_CXX17 + forward_list(forward_list&& _Right, const _Identity_t<_Alloc>& _Al) +#else + forward_list(forward_list&& _Right, const _Alloc& _Al) +#endif // _HAS_CXX17 + noexcept(_Alnode_traits::is_always_equal::value) // strengthened : _Mypair(_One_then_variadic_args_t{}, _Al) { if constexpr (!_Alty_traits::is_always_equal::value) { if (_Getal() != _Right._Getal()) { diff --git a/stl/inc/list b/stl/inc/list index 58f93ff9bb6..3fafa65d49c 100644 --- a/stl/inc/list +++ b/stl/inc/list @@ -11,6 +11,7 @@ #include #if _HAS_CXX17 +#include #include #endif // _HAS_CXX17 @@ -873,7 +874,13 @@ public: _Construct_range_unchecked(_Right._Unchecked_begin(), _Right._Unchecked_end()); } - list(const list& _Right, const _Alloc& _Al) : _Mypair(_One_then_variadic_args_t{}, _Al) { + +#if _HAS_CXX17 + list(const list& _Right, const _Identity_t<_Alloc>& _Al) +#else + list(const list& _Right, const _Alloc& _Al) +#endif // _HAS_CXX17 + : _Mypair(_One_then_variadic_args_t{}, _Al) { _Construct_range_unchecked(_Right._Unchecked_begin(), _Right._Unchecked_end()); } @@ -894,7 +901,12 @@ public: _Swap_val(_Right); } - list(list&& _Right, const _Alloc& _Al) : _Mypair(_One_then_variadic_args_t{}, _Al) { +#if _HAS_CXX17 + list(list&& _Right, const _Identity_t<_Alloc>& _Al) +#else + list(list&& _Right, const _Alloc& _Al) +#endif // _HAS_CXX17 + : _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 edf4c79772a..71e9a32785d 100644 --- a/stl/inc/queue +++ b/stl/inc/queue @@ -121,9 +121,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 @@ -307,7 +305,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; diff --git a/stl/inc/stack b/stl/inc/stack index 6a9a191ba8a..783da31347f 100644 --- a/stl/inc/stack +++ b/stl/inc/stack @@ -111,9 +111,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 4ec774e6f75..898038bd0f8 100644 --- a/stl/inc/vector +++ b/stl/inc/vector @@ -11,6 +11,7 @@ #include #if _HAS_CXX17 +#include #include #endif // _HAS_CXX17 @@ -527,7 +528,13 @@ public: _Construct_n(_Count, _Right_data._Myfirst, _Right_data._Mylast); } - _CONSTEXPR20_CONTAINER vector(const vector& _Right, const _Alloc& _Al) : _Mypair(_One_then_variadic_args_t{}, _Al) { + +#if _HAS_CXX17 + _CONSTEXPR20_CONTAINER vector(const vector& _Right, const _Identity_t<_Alloc>& _Al) +#else + _CONSTEXPR20_CONTAINER vector(const vector& _Right, const _Alloc& _Al) +#endif // _HAS_CXX17 + : _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); @@ -542,8 +549,13 @@ public: _Mypair._Myval2._Swap_proxy_and_iterators(_Right._Mypair._Myval2); } - _CONSTEXPR20_CONTAINER vector(vector&& _Right, const _Alloc& _Al_) noexcept( - _Alty_traits::is_always_equal::value) // strengthened + +#if _HAS_CXX17 + _CONSTEXPR20_CONTAINER vector(vector&& _Right, const _Identity_t<_Alloc>& _Al_) +#else + _CONSTEXPR20_CONTAINER vector(vector&& _Right, const _Alloc& _Al_) +#endif // _HAS_CXX17 + 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); @@ -2487,7 +2499,13 @@ public: _CONSTEXPR20_CONTAINER vector(const vector& _Right) : _Mybase(_Right) {} - _CONSTEXPR20_CONTAINER vector(const vector& _Right, const _Alloc& _Al) : _Mybase(_Right, _Al) {} +#if _HAS_CXX17 + _CONSTEXPR20_CONTAINER vector(const vector& _Right, const _Identity_t<_Alloc>& _Al) +#else + _CONSTEXPR20_CONTAINER vector(const vector& _Right, const _Alloc& _Al) +#endif // _HAS_CXX17 + : _Mybase(_Right, _Al) { + } template , int> = 0> _CONSTEXPR20_CONTAINER vector(_Iter _First, _Iter _Last, const _Alloc& _Al = _Alloc()) : _Mybase(_Al) { @@ -2504,8 +2522,12 @@ public: this->_Swap_proxy_and_iterators(_Right); } - _CONSTEXPR20_CONTAINER vector(vector&& _Right, const _Alloc& _Al) noexcept( - is_nothrow_constructible_v<_Mybase, _Mybase, const _Alloc&>) +#if _HAS_CXX17 + _CONSTEXPR20_CONTAINER vector(vector&& _Right, const _Identity_t<_Alloc>& _Al) +#else + _CONSTEXPR20_CONTAINER vector(vector&& _Right, const _Alloc& _Al) +#endif // _HAS_CXX17 + noexcept(is_nothrow_constructible_v<_Mybase, _Mybase, const _Alloc&>) : _Mybase(_STD move(_Right), _Al) { if constexpr (!_Alvbase_traits::is_always_equal::value) { if (this->_Getal() != _Right._Getal()) { diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index 97692b89373..46be93dc609 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 38896e23e0c..7a29300e6aa 100644 --- a/tests/std/test.lst +++ b/tests/std/test.lst @@ -417,6 +417,7 @@ tests\P1165R1_consistently_propagating_stateful_allocators tests\P1208R6_source_location tests\P1423R3_char8_t_remediation 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 00000000000..2de7aab2959 --- /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 00000000000..b21f65d85d5 --- /dev/null +++ b/tests/std/tests/P1518R2_stop_overconstraining_allocators/test.compile.pass.cpp @@ -0,0 +1,107 @@ +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +extern pmr::monotonic_buffer_resource mr; + +template