From 63eb68ab1ab3556760f64e252ffa77be2dcf8f83 Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Wed, 9 Jun 2021 16:38:37 +0200 Subject: [PATCH 01/14] Implement P1425 stack and queue constructors Addresses #1973 --- stl/inc/queue | 20 +++++ stl/inc/stack | 20 +++++ stl/inc/yvals_core.h | 3 + tests/std/test.lst | 1 + .../P1425R6_queue_stack_constructors/env.lst | 4 + .../P1425R6_queue_stack_constructors/test.cpp | 88 +++++++++++++++++++ 6 files changed, 136 insertions(+) create mode 100644 tests/std/tests/P1425R6_queue_stack_constructors/env.lst create mode 100644 tests/std/tests/P1425R6_queue_stack_constructors/test.cpp diff --git a/stl/inc/queue b/stl/inc/queue index edf4c79772a..0be6344a8b0 100644 --- a/stl/inc/queue +++ b/stl/inc/queue @@ -39,6 +39,12 @@ public: explicit queue(_Container&& _Cont) noexcept(is_nothrow_move_constructible_v<_Container>) // strengthened : c(_STD move(_Cont)) {} +#if _HAS_CXX23 + template , int> = 0> + queue(_InIt _First, _InIt _Last) noexcept(is_nothrow_constructible_v<_Container, _InIt, _InIt>) // strengthened + : c(_STD move(_First), _STD move(_Last)) {} +#endif // _HAS_CXX23 + template , int> = 0> explicit queue(const _Alloc& _Al) noexcept(is_nothrow_constructible_v<_Container, const _Alloc&>) // strengthened : c(_Al) {} @@ -59,6 +65,14 @@ public: is_nothrow_constructible_v<_Container, _Container, const _Alloc&>) // strengthened : c(_STD move(_Right.c), _Al) {} +#if _HAS_CXX23 + template , uses_allocator<_Container, _Alloc>>, int> = 0> + queue(_InIt _First, _InIt _Last, const _Alloc& _Al) noexcept( + is_nothrow_constructible_v<_Container, _InIt, _InIt, const _Alloc&>) // strengthened + : c(_STD move(_First), _STD move(_Last), _Al) {} +#endif // _HAS_CXX23 + _NODISCARD bool empty() const noexcept(noexcept(c.empty())) /* strengthened */ { return c.empty(); } @@ -173,6 +187,12 @@ void swap(queue<_Ty, _Container>& _Left, queue<_Ty, _Container>& _Right) noexcep template struct uses_allocator, _Alloc> : uses_allocator<_Container, _Alloc>::type {}; +#if _HAS_CXX23 +template >, + enable_if_t, _Is_allocator<_Alloc>>, int> = 0> +queue(_InIt, _InIt, _Alloc = _Alloc()) -> queue, deque, _Alloc>>; +#endif // _HAS_CXX23 + // CLASS TEMPLATE priority_queue template , class _Pr = less> class priority_queue { diff --git a/stl/inc/stack b/stl/inc/stack index 6a9a191ba8a..9414c7a4ea8 100644 --- a/stl/inc/stack +++ b/stl/inc/stack @@ -37,6 +37,12 @@ public: explicit stack(_Container&& _Cont) noexcept(is_nothrow_move_constructible_v<_Container>) // strengthened : c(_STD move(_Cont)) {} +#if _HAS_CXX23 + template , int> = 0> + stack(_InIt _First, _InIt _Last) noexcept(is_nothrow_constructible_v<_Container, _InIt, _InIt>) // strengthened + : c(_STD move(_First), _STD move(_Last)) {} +#endif // _HAS_CXX23 + template , int> = 0> explicit stack(const _Alloc& _Al) noexcept(is_nothrow_constructible_v<_Container, const _Alloc&>) // strengthened : c(_Al) {} @@ -57,6 +63,14 @@ public: is_nothrow_constructible_v<_Container, _Container, const _Alloc&>) // strengthened : c(_STD move(_Right.c), _Al) {} +#if _HAS_CXX23 + template , uses_allocator<_Container, _Alloc>>, int> = 0> + stack(_InIt _First, _InIt _Last, const _Alloc& _Al) noexcept( + is_nothrow_constructible_v<_Container, _InIt, _InIt, const _Alloc&>) // strengthened + : c(_STD move(_First), _STD move(_Last), _Al) {} +#endif // _HAS_CXX23 + _NODISCARD bool empty() const noexcept(noexcept(c.empty())) /* strengthened */ { return c.empty(); } @@ -162,6 +176,12 @@ void swap(stack<_Ty, _Container>& _Left, stack<_Ty, _Container>& _Right) noexcep template struct uses_allocator, _Alloc> : uses_allocator<_Container, _Alloc>::type {}; + +#if _HAS_CXX23 +template >, + enable_if_t, _Is_allocator<_Alloc>>, int> = 0> +stack(_InIt, _InIt, _Alloc = _Alloc()) -> stack, deque, _Alloc>>; +#endif // _HAS_CXX23 _STD_END #pragma pop_macro("new") diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index 3b2c62061be..e37e2fcf65f 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -255,6 +255,9 @@ // P1831R1 Deprecating volatile In The Standard Library // Other C++20 deprecation warnings +// _HAS_CXX23 directly controls: +// P1425R4 Iterator Pair Constructors For stack And queue + // Parallel Algorithms Notes // C++ allows an implementation to implement parallel algorithms as calls to the serial algorithms. // This implementation parallelizes several common algorithm calls, but not all. diff --git a/tests/std/test.lst b/tests/std/test.lst index cba3615d387..1e3cbdab49f 100644 --- a/tests/std/test.lst +++ b/tests/std/test.lst @@ -416,6 +416,7 @@ tests\P1135R6_semaphore tests\P1165R1_consistently_propagating_stateful_allocators tests\P1208R6_source_location tests\P1423R3_char8_t_remediation +tests\P1425R6_queue_stack_constructors tests\P1502R1_standard_library_header_units tests\P1614R2_spaceship tests\P1645R1_constexpr_numeric diff --git a/tests/std/tests/P1425R6_queue_stack_constructors/env.lst b/tests/std/tests/P1425R6_queue_stack_constructors/env.lst new file mode 100644 index 00000000000..642f530ffad --- /dev/null +++ b/tests/std/tests/P1425R6_queue_stack_constructors/env.lst @@ -0,0 +1,4 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +RUNALL_INCLUDE ..\usual_latest_matrix.lst diff --git a/tests/std/tests/P1425R6_queue_stack_constructors/test.cpp b/tests/std/tests/P1425R6_queue_stack_constructors/test.cpp new file mode 100644 index 00000000000..a9888b2610a --- /dev/null +++ b/tests/std/tests/P1425R6_queue_stack_constructors/test.cpp @@ -0,0 +1,88 @@ +// 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 +using namespace std; + +constexpr int some_data[] = {0, 1, 2, 3, 4, 5}; + +template +struct custom_allocator { + using value_type = T; + + custom_allocator() noexcept = default; + template + custom_allocator(const custom_allocator&) noexcept {} + + T* allocate(const size_t n) { + return allocator{}.allocate(n); + } + + void deallocate(T* const p, const size_t n) noexcept { + allocator{}.deallocate(p, n); + } + + template + void construct(T* const p, Args&&... args) { + construct_at(p, forward(args)...); + } +}; + +template +void test_container() { + Range range{begin(some_data), end(some_data)}; + + stack s1(range.begin(), range.end()); + static_assert(is_same_v>>>); + assert(s1.size() == size(some_data)); + int result = 5; + while (!s1.empty()) { + assert(s1.top() == result--); + s1.pop(); + } + + stack s2(range.begin(), range.end(), custom_allocator{}); + static_assert(is_same_v>>>); + assert(s2.size() == size(some_data)); + result = 5; + while (!s2.empty()) { + assert(s2.top() == result--); + s2.pop(); + } + + queue q1(range.begin(), range.end()); + static_assert(is_same_v>>>); + assert(q1.size() == size(some_data)); + result = 0; + while (!q1.empty()) { + assert(q1.front() == result++); + q1.pop(); + } + + queue q2(range.begin(), range.end(), custom_allocator{}); + static_assert(is_same_v>>>); + assert(q2.size() == size(some_data)); + result = 0; + while (!q2.empty()) { + assert(q2.front() == result++); + q2.pop(); + } +} + +int main() { + test_container>(); + test_container>(); + test_container>(); + test_container>(); +} From 0c910e3d27aea1f899aff1b4af5614b6e91e3f9d Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Wed, 9 Jun 2021 17:09:37 +0200 Subject: [PATCH 02/14] Adopt LWG-3506 Addresses #1965 --- stl/inc/queue | 43 +++++++++++ stl/inc/yvals_core.h | 1 + .../P1425R6_queue_stack_constructors/env.lst | 2 +- .../P1425R6_queue_stack_constructors/test.cpp | 75 ++++++++++++++++++- 4 files changed, 118 insertions(+), 3 deletions(-) diff --git a/stl/inc/queue b/stl/inc/queue index 0be6344a8b0..c619fcb2638 100644 --- a/stl/inc/queue +++ b/stl/inc/queue @@ -271,6 +271,33 @@ public: is_nothrow_move_constructible_v) // strengthened : c(_STD move(_Right.c), _Al), comp(_STD move(_Right.comp)) {} +#if _HAS_CXX20 + template , int> = 0> + priority_queue(_InIt _First, _InIt _Last, const _Pr& _Pred, const _Container& _Cont, const _Alloc& _Al) + : c(_Cont, _Al), comp(_Pred) { + c.insert(c.end(), _First, _Last); + _STD make_heap(c.begin(), c.end(), comp); + } + + template , int> = 0> + priority_queue(_InIt _First, _InIt _Last, const _Alloc& _Al) : c(_First, _Last, _Al), comp() { + _STD make_heap(c.begin(), c.end(), comp); + } + + template , int> = 0> + priority_queue(_InIt _First, _InIt _Last, const _Pr& _Pred, const _Alloc& _Al) + : c(_First, _Last, _Al), comp(_Pred) { + _STD make_heap(c.begin(), c.end(), comp); + } + + template , int> = 0> + priority_queue(_InIt _First, _InIt _Last, const _Pr& _Pred, _Container&& _Cont, const _Alloc& _Al) + : c(_STD move(_Cont), _Al), comp(_Pred) { + c.insert(c.end(), _First, _Last); + _STD make_heap(c.begin(), c.end(), comp); + } +#endif // _HAS_CXX20 + _NODISCARD bool empty() const noexcept(noexcept(c.empty())) /* strengthened */ { return c.empty(); } @@ -333,6 +360,22 @@ template priority_queue; #endif // _HAS_CXX17 +#if _HAS_CXX20 +template , _Is_allocator<_Alloc>>, int> = 0> +priority_queue(_Iter, _Iter, _Alloc) + -> priority_queue<_Iter_value_t<_Iter>, vector<_Iter_value_t<_Iter>, _Alloc>, less<_Iter_value_t<_Iter>>>; + +template , _Is_allocator<_Alloc>>, int> = 0> +priority_queue(_Iter, _Iter, Compare, _Alloc) + -> priority_queue<_Iter_value_t<_Iter>, vector<_Iter_value_t<_Iter>, _Alloc>, Compare>; + +template , _Is_allocator<_Alloc>>, int> = 0> +priority_queue(_Iter, _Iter, Compare, Container, _Alloc) + -> priority_queue; +#endif // _HAS_CXX20 + template ::value && _Is_swappable<_Pr>::value, int> = 0> void swap(priority_queue<_Ty, _Container, _Pr>& _Left, priority_queue<_Ty, _Container, _Pr>& _Right) noexcept( diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index e37e2fcf65f..33febab8405 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -249,6 +249,7 @@ // _HAS_CXX20 indirectly controls: // P0619R4 Removing C++17-Deprecated Features +// LWG-3506 Missing allocator-extended constructors for priority_queue // _HAS_CXX20 and _SILENCE_ALL_CXX20_DEPRECATION_WARNINGS control: // P0767R1 Deprecating is_pod diff --git a/tests/std/tests/P1425R6_queue_stack_constructors/env.lst b/tests/std/tests/P1425R6_queue_stack_constructors/env.lst index 642f530ffad..351a8293d9d 100644 --- a/tests/std/tests/P1425R6_queue_stack_constructors/env.lst +++ b/tests/std/tests/P1425R6_queue_stack_constructors/env.lst @@ -1,4 +1,4 @@ # Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -RUNALL_INCLUDE ..\usual_latest_matrix.lst +RUNALL_INCLUDE ..\usual_20_matrix.lst diff --git a/tests/std/tests/P1425R6_queue_stack_constructors/test.cpp b/tests/std/tests/P1425R6_queue_stack_constructors/test.cpp index a9888b2610a..5385ac8c06c 100644 --- a/tests/std/tests/P1425R6_queue_stack_constructors/test.cpp +++ b/tests/std/tests/P1425R6_queue_stack_constructors/test.cpp @@ -15,7 +15,8 @@ #include using namespace std; -constexpr int some_data[] = {0, 1, 2, 3, 4, 5}; +constexpr int some_data[] = {0, 1, 2, 3, 4, 5}; +constexpr int additional_data[] = {6, 7, 8, 9, 10, 11}; template struct custom_allocator { @@ -43,10 +44,12 @@ template void test_container() { Range range{begin(some_data), end(some_data)}; + int result; +#if _HAS_CXX23 stack s1(range.begin(), range.end()); static_assert(is_same_v>>>); assert(s1.size() == size(some_data)); - int result = 5; + result = 5; while (!s1.empty()) { assert(s1.top() == result--); s1.pop(); @@ -78,6 +81,74 @@ void test_container() { assert(q2.front() == result++); q2.pop(); } +#endif // _HAS_CXX23 + + priority_queue pq1(range.begin(), range.end()); + static_assert(is_same_v>, less>>); + assert(pq1.size() == size(some_data)); + result = 5; + while (!pq1.empty()) { + assert(pq1.top() == result--); + pq1.pop(); + } + + priority_queue pq2(range.begin(), range.end(), custom_allocator{}); + static_assert(is_same_v>, less>>); + assert(pq2.size() == size(some_data)); + result = 5; + while (!pq2.empty()) { + assert(pq2.top() == result--); + pq2.pop(); + } + + priority_queue pq3(range.begin(), range.end(), greater{}, custom_allocator{}); + static_assert(is_same_v>, greater>>); + assert(pq3.size() == size(some_data)); + result = 0; + while (!pq3.empty()) { + assert(pq3.top() == result++); + pq3.pop(); + } + + vector cont(begin(additional_data), end(additional_data)); + priority_queue pq4(range.begin(), range.end(), greater{}, cont); + static_assert(is_same_v>, greater>>); + assert(pq4.size() == size(some_data) + size(additional_data)); + result = 0; + while (!pq4.empty()) { + assert(pq4.top() == result++); + pq4.pop(); + } + + priority_queue pq5(range.begin(), range.end(), greater{}, + vector>{begin(additional_data), end(additional_data)}); + static_assert(is_same_v>, greater>>); + assert(pq5.size() == size(some_data) + size(additional_data)); + result = 0; + while (!pq5.empty()) { + assert(pq5.top() == result++); + pq5.pop(); + } + + vector cont2(begin(additional_data), end(additional_data), custom_allocator{}); + priority_queue pq6(range.begin(), range.end(), greater{}, cont2, custom_allocator{}); + static_assert(is_same_v>, greater>>); + assert(pq6.size() == size(some_data) + size(additional_data)); + result = 0; + while (!pq6.empty()) { + assert(pq6.top() == result++); + pq6.pop(); + } + + priority_queue pq7(range.begin(), range.end(), greater{}, + vector>{begin(additional_data), end(additional_data)}, custom_allocator{}); + static_assert(is_same_v>, greater>>); + assert(pq7.size() == size(some_data) + size(additional_data)); + result = 0; + while (!pq7.empty()) { + assert(pq7.top() == result++); + pq7.pop(); + } } int main() { From 43b0e58f05f5f8a0510aa025964c8f4424d7c2ab Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Wed, 9 Jun 2021 17:26:17 +0200 Subject: [PATCH 03/14] Adopt LWG-3522 Addresses #1965 --- stl/inc/queue | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stl/inc/queue b/stl/inc/queue index c619fcb2638..b3338bac0a1 100644 --- a/stl/inc/queue +++ b/stl/inc/queue @@ -220,23 +220,23 @@ public: _STD make_heap(c.begin(), c.end(), comp); } - template + template , int> = 0> priority_queue(_InIt _First, _InIt _Last, const _Pr& _Pred, const _Container& _Cont) : c(_Cont), comp(_Pred) { c.insert(c.end(), _First, _Last); _STD make_heap(c.begin(), c.end(), comp); } - template + template , int> = 0> priority_queue(_InIt _First, _InIt _Last) : c(_First, _Last), comp() { _STD make_heap(c.begin(), c.end(), comp); } - template + template , int> = 0> priority_queue(_InIt _First, _InIt _Last, const _Pr& _Pred) : c(_First, _Last), comp(_Pred) { _STD make_heap(c.begin(), c.end(), comp); } - template + template , int> = 0> priority_queue(_InIt _First, _InIt _Last, const _Pr& _Pred, _Container&& _Cont) : c(_STD move(_Cont)), comp(_Pred) { c.insert(c.end(), _First, _Last); _STD make_heap(c.begin(), c.end(), comp); From a34d8fa10ef6e3aef9c7b3618672debb3289eaa9 Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Wed, 9 Jun 2021 20:44:31 +0200 Subject: [PATCH 04/14] Use _Iter_value_t rather than iter_value_t --- stl/inc/queue | 4 ++-- stl/inc/stack | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/stl/inc/queue b/stl/inc/queue index b3338bac0a1..7cebb25f3e7 100644 --- a/stl/inc/queue +++ b/stl/inc/queue @@ -188,9 +188,9 @@ template struct uses_allocator, _Alloc> : uses_allocator<_Container, _Alloc>::type {}; #if _HAS_CXX23 -template >, +template >, enable_if_t, _Is_allocator<_Alloc>>, int> = 0> -queue(_InIt, _InIt, _Alloc = _Alloc()) -> queue, deque, _Alloc>>; +queue(_InIt, _InIt, _Alloc = _Alloc()) -> queue<_Iter_value_t<_InIt>, deque<_Iter_value_t<_InIt>, _Alloc>>; #endif // _HAS_CXX23 // CLASS TEMPLATE priority_queue diff --git a/stl/inc/stack b/stl/inc/stack index 9414c7a4ea8..347f0fdbd7f 100644 --- a/stl/inc/stack +++ b/stl/inc/stack @@ -178,9 +178,9 @@ template struct uses_allocator, _Alloc> : uses_allocator<_Container, _Alloc>::type {}; #if _HAS_CXX23 -template >, +template >, enable_if_t, _Is_allocator<_Alloc>>, int> = 0> -stack(_InIt, _InIt, _Alloc = _Alloc()) -> stack, deque, _Alloc>>; +stack(_InIt, _InIt, _Alloc = _Alloc()) -> stack<_Iter_value_t<_InIt>, deque<_Iter_value_t<_InIt>, _Alloc>>; #endif // _HAS_CXX23 _STD_END From 239467d34a602482ca1ce33f2ae0bd35d24d7f83 Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Thu, 10 Jun 2021 14:00:00 +0200 Subject: [PATCH 05/14] drop mentions in yvals_core --- stl/inc/yvals_core.h | 1 - 1 file changed, 1 deletion(-) diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index 33febab8405..e37e2fcf65f 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -249,7 +249,6 @@ // _HAS_CXX20 indirectly controls: // P0619R4 Removing C++17-Deprecated Features -// LWG-3506 Missing allocator-extended constructors for priority_queue // _HAS_CXX20 and _SILENCE_ALL_CXX20_DEPRECATION_WARNINGS control: // P0767R1 Deprecating is_pod From ccdf327360d6bea4747c47380a7a3e5f49695a06 Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Sat, 12 Jun 2021 11:17:30 +0200 Subject: [PATCH 06/14] Add feature test macro --- stl/inc/yvals_core.h | 4 ++++ .../test.compile.pass.cpp | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index 006f0a70d65..e6474125e10 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -1307,6 +1307,10 @@ #define __cpp_lib_unwrap_ref 201811L #endif // _HAS_CXX20 +#if _HAS_CXX23 +#define __cpp_lib_adaptor_iterator_pair_constructor 202106L +#endif // _HAS_CXX23 + #ifndef _M_CEE #if _HAS_CXX20 #define __cpp_lib_execution 201902L // P1001R2 execution::unseq diff --git a/tests/std/tests/VSO_0157762_feature_test_macros/test.compile.pass.cpp b/tests/std/tests/VSO_0157762_feature_test_macros/test.compile.pass.cpp index 0da859a6bf9..de75dcfc2af 100644 --- a/tests/std/tests/VSO_0157762_feature_test_macros/test.compile.pass.cpp +++ b/tests/std/tests/VSO_0157762_feature_test_macros/test.compile.pass.cpp @@ -8,6 +8,19 @@ int main() {} // COMPILE-ONLY // LIBRARY FEATURE-TEST MACROS +#if _HAS_CXX23 +#ifndef __cpp_lib_adaptor_iterator_pair_constructor +#error __cpp_lib_adaptor_iterator_pair_constructor is not defined +#elif __cpp_lib_adaptor_iterator_pair_constructor != 202106L +#error __cpp_lib_adaptor_iterator_pair_constructor is not 202106L +#else +STATIC_ASSERT(__cpp_lib_adaptor_iterator_pair_constructor == 202106L); +#endif +#else +#ifdef __cpp_lib_adaptor_iterator_pair_constructor +#error __cpp_lib_adaptor_iterator_pair_constructor is defined +#endif +#endif #ifndef __cpp_lib_addressof_constexpr #error __cpp_lib_addressof_constexpr is not defined From 0cd5770e23b57bfff33c26e6f51e05a474c71b03 Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Tue, 22 Jun 2021 13:48:17 +0200 Subject: [PATCH 07/14] Use the right paper name --- tests/std/test.lst | 2 +- .../env.lst | 0 .../test.cpp | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename tests/std/tests/{P1425R6_queue_stack_constructors => P1425R4_queue_stack_constructors}/env.lst (100%) rename tests/std/tests/{P1425R6_queue_stack_constructors => P1425R4_queue_stack_constructors}/test.cpp (100%) diff --git a/tests/std/test.lst b/tests/std/test.lst index 1e3cbdab49f..39869ce43f0 100644 --- a/tests/std/test.lst +++ b/tests/std/test.lst @@ -416,7 +416,7 @@ tests\P1135R6_semaphore tests\P1165R1_consistently_propagating_stateful_allocators tests\P1208R6_source_location tests\P1423R3_char8_t_remediation -tests\P1425R6_queue_stack_constructors +tests\P1425R4_queue_stack_constructors tests\P1502R1_standard_library_header_units tests\P1614R2_spaceship tests\P1645R1_constexpr_numeric diff --git a/tests/std/tests/P1425R6_queue_stack_constructors/env.lst b/tests/std/tests/P1425R4_queue_stack_constructors/env.lst similarity index 100% rename from tests/std/tests/P1425R6_queue_stack_constructors/env.lst rename to tests/std/tests/P1425R4_queue_stack_constructors/env.lst diff --git a/tests/std/tests/P1425R6_queue_stack_constructors/test.cpp b/tests/std/tests/P1425R4_queue_stack_constructors/test.cpp similarity index 100% rename from tests/std/tests/P1425R6_queue_stack_constructors/test.cpp rename to tests/std/tests/P1425R4_queue_stack_constructors/test.cpp From a9e8c3d264435d20d454eb912735c0d4b24da497 Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Tue, 22 Jun 2021 14:20:17 +0200 Subject: [PATCH 08/14] Apply STLs review comments --- stl/inc/queue | 55 ++++++++--------- .../P1425R4_queue_stack_constructors/env.lst | 2 +- .../P1425R4_queue_stack_constructors/test.cpp | 61 ++++++++++++++++--- 3 files changed, 79 insertions(+), 39 deletions(-) diff --git a/stl/inc/queue b/stl/inc/queue index 7cebb25f3e7..5700e6a1d4e 100644 --- a/stl/inc/queue +++ b/stl/inc/queue @@ -271,32 +271,34 @@ public: is_nothrow_move_constructible_v) // strengthened : c(_STD move(_Right.c), _Al), comp(_STD move(_Right.comp)) {} -#if _HAS_CXX20 - template , int> = 0> - priority_queue(_InIt _First, _InIt _Last, const _Pr& _Pred, const _Container& _Cont, const _Alloc& _Al) - : c(_Cont, _Al), comp(_Pred) { - c.insert(c.end(), _First, _Last); - _STD make_heap(c.begin(), c.end(), comp); - } - - template , int> = 0> + template && uses_allocator_v<_Container, _Alloc>, int> = 0> priority_queue(_InIt _First, _InIt _Last, const _Alloc& _Al) : c(_First, _Last, _Al), comp() { _STD make_heap(c.begin(), c.end(), comp); } - template , int> = 0> + template && uses_allocator_v<_Container, _Alloc>, int> = 0> priority_queue(_InIt _First, _InIt _Last, const _Pr& _Pred, const _Alloc& _Al) : c(_First, _Last, _Al), comp(_Pred) { _STD make_heap(c.begin(), c.end(), comp); } - template , int> = 0> + template && uses_allocator_v<_Container, _Alloc>, int> = 0> + priority_queue(_InIt _First, _InIt _Last, const _Pr& _Pred, const _Container& _Cont, const _Alloc& _Al) + : c(_Cont, _Al), comp(_Pred) { + c.insert(c.end(), _First, _Last); + _STD make_heap(c.begin(), c.end(), comp); + } + + template && uses_allocator_v<_Container, _Alloc>, int> = 0> priority_queue(_InIt _First, _InIt _Last, const _Pr& _Pred, _Container&& _Cont, const _Alloc& _Al) : c(_STD move(_Cont), _Al), comp(_Pred) { c.insert(c.end(), _First, _Last); _STD make_heap(c.begin(), c.end(), comp); } -#endif // _HAS_CXX20 _NODISCARD bool empty() const noexcept(noexcept(c.empty())) /* strengthened */ { return c.empty(); @@ -358,23 +360,20 @@ template >, int> = 0> priority_queue(_Pr, _Container, _Alloc) -> priority_queue; -#endif // _HAS_CXX17 -#if _HAS_CXX20 -template , _Is_allocator<_Alloc>>, int> = 0> -priority_queue(_Iter, _Iter, _Alloc) - -> priority_queue<_Iter_value_t<_Iter>, vector<_Iter_value_t<_Iter>, _Alloc>, less<_Iter_value_t<_Iter>>>; - -template , _Is_allocator<_Alloc>>, int> = 0> -priority_queue(_Iter, _Iter, Compare, _Alloc) - -> priority_queue<_Iter_value_t<_Iter>, vector<_Iter_value_t<_Iter>, _Alloc>, Compare>; - -template , _Is_allocator<_Alloc>>, int> = 0> -priority_queue(_Iter, _Iter, Compare, Container, _Alloc) - -> priority_queue; -#endif // _HAS_CXX20 +template , _Alloc>, + enable_if_t, _Is_allocator<_Alloc>, uses_allocator<_Container, _Alloc>>, int> = 0> +priority_queue(_Iter, _Iter, _Alloc) -> priority_queue<_Iter_value_t<_Iter>, _Container, less<_Iter_value_t<_Iter>>>; + +template , _Alloc>, + enable_if_t, _Is_allocator<_Alloc>, uses_allocator<_Container, _Alloc>>, int> = 0> +priority_queue(_Iter, _Iter, _Compare, _Alloc) -> priority_queue<_Iter_value_t<_Iter>, _Container, _Compare>; + +template , _Is_allocator<_Alloc>, uses_allocator<_Container, _Alloc>>, int> = 0> +priority_queue(_Iter, _Iter, _Compare, _Container, _Alloc) + -> priority_queue; +#endif // _HAS_CXX17 template ::value && _Is_swappable<_Pr>::value, int> = 0> diff --git a/tests/std/tests/P1425R4_queue_stack_constructors/env.lst b/tests/std/tests/P1425R4_queue_stack_constructors/env.lst index 351a8293d9d..19f025bd0e6 100644 --- a/tests/std/tests/P1425R4_queue_stack_constructors/env.lst +++ b/tests/std/tests/P1425R4_queue_stack_constructors/env.lst @@ -1,4 +1,4 @@ # Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -RUNALL_INCLUDE ..\usual_20_matrix.lst +RUNALL_INCLUDE ..\usual_matrix.lst diff --git a/tests/std/tests/P1425R4_queue_stack_constructors/test.cpp b/tests/std/tests/P1425R4_queue_stack_constructors/test.cpp index 5385ac8c06c..c5ee0ba725b 100644 --- a/tests/std/tests/P1425R4_queue_stack_constructors/test.cpp +++ b/tests/std/tests/P1425R4_queue_stack_constructors/test.cpp @@ -34,10 +34,17 @@ struct custom_allocator { allocator{}.deallocate(p, n); } - template - void construct(T* const p, Args&&... args) { - construct_at(p, forward(args)...); + template + bool operator==(const custom_allocator&) noexcept { + return is_same_v; } + +#if !_HAS_CXX20 + template + bool operator!=(const custom_allocator&) noexcept { + return !is_same_v; + } +#endif // !_HAS_CXX20 }; template @@ -83,8 +90,12 @@ void test_container() { } #endif // _HAS_CXX23 +#if _HAS_CXX17 priority_queue pq1(range.begin(), range.end()); - static_assert(is_same_v>, less>>); + static_assert(is_same_v, less>>); +#else // ^^^_HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv + priority_queue, less> pq1(range.begin(), range.end()); +#endif // !_HAS_CXX17 assert(pq1.size() == size(some_data)); result = 5; while (!pq1.empty()) { @@ -92,8 +103,13 @@ void test_container() { pq1.pop(); } +#if _HAS_CXX17 priority_queue pq2(range.begin(), range.end(), custom_allocator{}); static_assert(is_same_v>, less>>); +#else // ^^^_HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv + priority_queue>, less> pq2( + range.begin(), range.end(), custom_allocator{}); +#endif // !_HAS_CXX17 assert(pq2.size() == size(some_data)); result = 5; while (!pq2.empty()) { @@ -101,8 +117,13 @@ void test_container() { pq2.pop(); } +#if _HAS_CXX17 priority_queue pq3(range.begin(), range.end(), greater{}, custom_allocator{}); static_assert(is_same_v>, greater>>); +#else // ^^^_HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv + priority_queue>, greater> pq3( + range.begin(), range.end(), greater{}, custom_allocator{}); +#endif // !_HAS_CXX17 assert(pq3.size() == size(some_data)); result = 0; while (!pq3.empty()) { @@ -110,9 +131,13 @@ void test_container() { pq3.pop(); } - vector cont(begin(additional_data), end(additional_data)); + vector cont(begin(additional_data), end(additional_data)); +#if _HAS_CXX17 priority_queue pq4(range.begin(), range.end(), greater{}, cont); - static_assert(is_same_v>, greater>>); + static_assert(is_same_v, greater>>); +#else // ^^^_HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv + priority_queue, greater> pq4(range.begin(), range.end(), greater{}, cont); +#endif // !_HAS_CXX17 assert(pq4.size() == size(some_data) + size(additional_data)); result = 0; while (!pq4.empty()) { @@ -120,9 +145,14 @@ void test_container() { pq4.pop(); } - priority_queue pq5(range.begin(), range.end(), greater{}, - vector>{begin(additional_data), end(additional_data)}); - static_assert(is_same_v>, greater>>); +#if _HAS_CXX17 + priority_queue pq5( + range.begin(), range.end(), greater{}, vector{begin(additional_data), end(additional_data)}); + static_assert(is_same_v, greater>>); +#else // ^^^_HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv + priority_queue, greater> pq5( + range.begin(), range.end(), greater{}, vector{begin(additional_data), end(additional_data)}); +#endif // !_HAS_CXX17 assert(pq5.size() == size(some_data) + size(additional_data)); result = 0; while (!pq5.empty()) { @@ -130,9 +160,14 @@ void test_container() { pq5.pop(); } - vector cont2(begin(additional_data), end(additional_data), custom_allocator{}); + vector> cont2(begin(additional_data), end(additional_data), custom_allocator{}); +#if _HAS_CXX17 priority_queue pq6(range.begin(), range.end(), greater{}, cont2, custom_allocator{}); static_assert(is_same_v>, greater>>); +#else // ^^^_HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv + priority_queue>, greater> pq6( + range.begin(), range.end(), greater{}, cont2, custom_allocator{}); +#endif // !_HAS_CXX17 assert(pq6.size() == size(some_data) + size(additional_data)); result = 0; while (!pq6.empty()) { @@ -140,9 +175,15 @@ void test_container() { pq6.pop(); } +#if _HAS_CXX17 priority_queue pq7(range.begin(), range.end(), greater{}, vector>{begin(additional_data), end(additional_data)}, custom_allocator{}); static_assert(is_same_v>, greater>>); +#else // ^^^_HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv + priority_queue>, greater> pq7(range.begin(), range.end(), + greater{}, vector>{begin(additional_data), end(additional_data)}, + custom_allocator{}); +#endif // !_HAS_CXX17 assert(pq7.size() == size(some_data) + size(additional_data)); result = 0; while (!pq7.empty()) { From 55cea370a7257bc6fe7743cf7848a97b5cf6d3be Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Sun, 18 Jul 2021 08:40:21 +0200 Subject: [PATCH 09/14] Adopt P1518R2 Stop Overconstraining Allocators In Container Deduction Guides --- stl/inc/queue | 8 ++++---- stl/inc/stack | 4 +--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/stl/inc/queue b/stl/inc/queue index 5700e6a1d4e..5fd0cd231a2 100644 --- a/stl/inc/queue +++ b/stl/inc/queue @@ -356,21 +356,21 @@ 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; template , _Alloc>, - enable_if_t, _Is_allocator<_Alloc>, uses_allocator<_Container, _Alloc>>, int> = 0> + enable_if_t, uses_allocator<_Container, _Alloc>>, int> = 0> priority_queue(_Iter, _Iter, _Alloc) -> priority_queue<_Iter_value_t<_Iter>, _Container, less<_Iter_value_t<_Iter>>>; template , _Alloc>, - enable_if_t, _Is_allocator<_Alloc>, uses_allocator<_Container, _Alloc>>, int> = 0> + enable_if_t, uses_allocator<_Container, _Alloc>>, int> = 0> priority_queue(_Iter, _Iter, _Compare, _Alloc) -> 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 347f0fdbd7f..902f8b84243 100644 --- a/stl/inc/stack +++ b/stl/inc/stack @@ -125,9 +125,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 From 3fdb41944b0a2b6c173fe8fbab1cb6da4c13db23 Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Sun, 18 Jul 2021 11:51:52 +0200 Subject: [PATCH 10/14] Revert "Adopt P1518R2 Stop Overconstraining Allocators In Container Deduction Guides" This reverts commit 55cea370a7257bc6fe7743cf7848a97b5cf6d3be. --- stl/inc/queue | 8 ++++---- stl/inc/stack | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/stl/inc/queue b/stl/inc/queue index 5fd0cd231a2..5700e6a1d4e 100644 --- a/stl/inc/queue +++ b/stl/inc/queue @@ -356,21 +356,21 @@ priority_queue(_Iter, _Iter, _Pr = _Pr(), _Container = _Container()) -> priority_queue<_Iter_value_t<_Iter>, _Container, _Pr>; template >, negation<_Is_allocator<_Container>>, + enable_if_t>, negation<_Is_allocator<_Container>>, _Is_allocator<_Alloc>, uses_allocator<_Container, _Alloc>>, int> = 0> priority_queue(_Pr, _Container, _Alloc) -> priority_queue; template , _Alloc>, - enable_if_t, uses_allocator<_Container, _Alloc>>, int> = 0> + enable_if_t, _Is_allocator<_Alloc>, uses_allocator<_Container, _Alloc>>, int> = 0> priority_queue(_Iter, _Iter, _Alloc) -> priority_queue<_Iter_value_t<_Iter>, _Container, less<_Iter_value_t<_Iter>>>; template , _Alloc>, - enable_if_t, uses_allocator<_Container, _Alloc>>, int> = 0> + enable_if_t, _Is_allocator<_Alloc>, uses_allocator<_Container, _Alloc>>, int> = 0> priority_queue(_Iter, _Iter, _Compare, _Alloc) -> priority_queue<_Iter_value_t<_Iter>, _Container, _Compare>; template , uses_allocator<_Container, _Alloc>>, int> = 0> + enable_if_t, _Is_allocator<_Alloc>, 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 902f8b84243..347f0fdbd7f 100644 --- a/stl/inc/stack +++ b/stl/inc/stack @@ -125,7 +125,9 @@ template ::value, int> stack(_Container) -> stack; template >, uses_allocator<_Container, _Alloc>>, int> = 0> + enable_if_t< + conjunction_v>, _Is_allocator<_Alloc>, uses_allocator<_Container, _Alloc>>, + int> = 0> stack(_Container, _Alloc) -> stack; #endif // _HAS_CXX17 From f58bad73dc7d693ddad2715e87f1815760a5fbd3 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Thu, 12 Aug 2021 19:38:38 -0700 Subject: [PATCH 11/14] Code review feedback. --- stl/inc/queue | 12 ++-- stl/inc/stack | 12 ++-- stl/inc/yvals_core.h | 6 +- .../P1425R4_queue_stack_constructors/test.cpp | 56 +++++++++---------- 4 files changed, 41 insertions(+), 45 deletions(-) diff --git a/stl/inc/queue b/stl/inc/queue index 7e813430a6f..e0583c98db7 100644 --- a/stl/inc/queue +++ b/stl/inc/queue @@ -140,6 +140,12 @@ template queue; #endif // _HAS_CXX17 +#if _HAS_CXX23 +template >, + enable_if_t, _Is_allocator<_Alloc>>, int> = 0> +queue(_InIt, _InIt, _Alloc = _Alloc()) -> queue<_Iter_value_t<_InIt>, deque<_Iter_value_t<_InIt>, _Alloc>>; +#endif // _HAS_CXX23 + template _NODISCARD bool operator==(const queue<_Ty, _Container>& _Left, const queue<_Ty, _Container>& _Right) { return _Left._Get_container() == _Right._Get_container(); @@ -186,12 +192,6 @@ void swap(queue<_Ty, _Container>& _Left, queue<_Ty, _Container>& _Right) noexcep template struct uses_allocator, _Alloc> : uses_allocator<_Container, _Alloc>::type {}; -#if _HAS_CXX23 -template >, - enable_if_t, _Is_allocator<_Alloc>>, int> = 0> -queue(_InIt, _InIt, _Alloc = _Alloc()) -> queue<_Iter_value_t<_InIt>, deque<_Iter_value_t<_InIt>, _Alloc>>; -#endif // _HAS_CXX23 - template , class _Pr = less> class priority_queue { public: diff --git a/stl/inc/stack b/stl/inc/stack index 93b0600c0e5..6a4a5e9f9bb 100644 --- a/stl/inc/stack +++ b/stl/inc/stack @@ -130,6 +130,12 @@ template stack; #endif // _HAS_CXX17 +#if _HAS_CXX23 +template >, + enable_if_t, _Is_allocator<_Alloc>>, int> = 0> +stack(_InIt, _InIt, _Alloc = _Alloc()) -> stack<_Iter_value_t<_InIt>, deque<_Iter_value_t<_InIt>, _Alloc>>; +#endif // _HAS_CXX23 + template _NODISCARD bool operator==(const stack<_Ty, _Container>& _Left, const stack<_Ty, _Container>& _Right) { return _Left._Get_container() == _Right._Get_container(); @@ -175,12 +181,6 @@ void swap(stack<_Ty, _Container>& _Left, stack<_Ty, _Container>& _Right) noexcep template struct uses_allocator, _Alloc> : uses_allocator<_Container, _Alloc>::type {}; - -#if _HAS_CXX23 -template >, - enable_if_t, _Is_allocator<_Alloc>>, int> = 0> -stack(_InIt, _InIt, _Alloc = _Alloc()) -> stack<_Iter_value_t<_InIt>, deque<_Iter_value_t<_InIt>, _Alloc>>; -#endif // _HAS_CXX23 _STD_END #pragma pop_macro("new") diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index 07a18f431ed..9665e76d63f 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -1319,10 +1319,6 @@ #define __cpp_lib_unwrap_ref 201811L #endif // _HAS_CXX20 -#if _HAS_CXX23 -#define __cpp_lib_adaptor_iterator_pair_constructor 202106L -#endif // _HAS_CXX23 - #ifndef _M_CEE #if _HAS_CXX20 #define __cpp_lib_execution 201902L // P1001R2 execution::unseq @@ -1357,6 +1353,8 @@ // C++23 #if _HAS_CXX23 +#define __cpp_lib_adaptor_iterator_pair_constructor 202106L + #ifdef __cpp_lib_concepts #define __cpp_lib_allocate_at_least 202106L #endif // __cpp_lib_concepts diff --git a/tests/std/tests/P1425R4_queue_stack_constructors/test.cpp b/tests/std/tests/P1425R4_queue_stack_constructors/test.cpp index c5ee0ba725b..39399bc1f05 100644 --- a/tests/std/tests/P1425R4_queue_stack_constructors/test.cpp +++ b/tests/std/tests/P1425R4_queue_stack_constructors/test.cpp @@ -1,17 +1,16 @@ // 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 #include using namespace std; @@ -35,14 +34,14 @@ struct custom_allocator { } template - bool operator==(const custom_allocator&) noexcept { - return is_same_v; + bool operator==(const custom_allocator&) const noexcept { + return true; } #if !_HAS_CXX20 template - bool operator!=(const custom_allocator&) noexcept { - return !is_same_v; + bool operator!=(const custom_allocator&) const noexcept { + return false; } #endif // !_HAS_CXX20 }; @@ -93,7 +92,7 @@ void test_container() { #if _HAS_CXX17 priority_queue pq1(range.begin(), range.end()); static_assert(is_same_v, less>>); -#else // ^^^_HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv +#else // ^^^ _HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv priority_queue, less> pq1(range.begin(), range.end()); #endif // !_HAS_CXX17 assert(pq1.size() == size(some_data)); @@ -106,7 +105,7 @@ void test_container() { #if _HAS_CXX17 priority_queue pq2(range.begin(), range.end(), custom_allocator{}); static_assert(is_same_v>, less>>); -#else // ^^^_HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv +#else // ^^^ _HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv priority_queue>, less> pq2( range.begin(), range.end(), custom_allocator{}); #endif // !_HAS_CXX17 @@ -120,7 +119,7 @@ void test_container() { #if _HAS_CXX17 priority_queue pq3(range.begin(), range.end(), greater{}, custom_allocator{}); static_assert(is_same_v>, greater>>); -#else // ^^^_HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv +#else // ^^^ _HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv priority_queue>, greater> pq3( range.begin(), range.end(), greater{}, custom_allocator{}); #endif // !_HAS_CXX17 @@ -131,12 +130,12 @@ void test_container() { pq3.pop(); } - vector cont(begin(additional_data), end(additional_data)); + deque cont(begin(additional_data), end(additional_data)); #if _HAS_CXX17 priority_queue pq4(range.begin(), range.end(), greater{}, cont); - static_assert(is_same_v, greater>>); -#else // ^^^_HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv - priority_queue, greater> pq4(range.begin(), range.end(), greater{}, cont); + static_assert(is_same_v, greater>>); +#else // ^^^ _HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv + priority_queue, greater> pq4(range.begin(), range.end(), greater{}, cont); #endif // !_HAS_CXX17 assert(pq4.size() == size(some_data) + size(additional_data)); result = 0; @@ -147,11 +146,11 @@ void test_container() { #if _HAS_CXX17 priority_queue pq5( - range.begin(), range.end(), greater{}, vector{begin(additional_data), end(additional_data)}); - static_assert(is_same_v, greater>>); -#else // ^^^_HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv - priority_queue, greater> pq5( - range.begin(), range.end(), greater{}, vector{begin(additional_data), end(additional_data)}); + range.begin(), range.end(), greater{}, deque{begin(additional_data), end(additional_data)}); + static_assert(is_same_v, greater>>); +#else // ^^^ _HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv + priority_queue, greater> pq5( + range.begin(), range.end(), greater{}, deque{begin(additional_data), end(additional_data)}); #endif // !_HAS_CXX17 assert(pq5.size() == size(some_data) + size(additional_data)); result = 0; @@ -160,12 +159,12 @@ void test_container() { pq5.pop(); } - vector> cont2(begin(additional_data), end(additional_data), custom_allocator{}); + deque> cont2(begin(additional_data), end(additional_data), custom_allocator{}); #if _HAS_CXX17 priority_queue pq6(range.begin(), range.end(), greater{}, cont2, custom_allocator{}); - static_assert(is_same_v>, greater>>); -#else // ^^^_HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv - priority_queue>, greater> pq6( + static_assert(is_same_v>, greater>>); +#else // ^^^ _HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv + priority_queue>, greater> pq6( range.begin(), range.end(), greater{}, cont2, custom_allocator{}); #endif // !_HAS_CXX17 assert(pq6.size() == size(some_data) + size(additional_data)); @@ -177,12 +176,11 @@ void test_container() { #if _HAS_CXX17 priority_queue pq7(range.begin(), range.end(), greater{}, - vector>{begin(additional_data), end(additional_data)}, custom_allocator{}); - static_assert(is_same_v>, greater>>); -#else // ^^^_HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv - priority_queue>, greater> pq7(range.begin(), range.end(), - greater{}, vector>{begin(additional_data), end(additional_data)}, - custom_allocator{}); + deque>{begin(additional_data), end(additional_data)}, custom_allocator{}); + static_assert(is_same_v>, greater>>); +#else // ^^^ _HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv + priority_queue>, greater> pq7(range.begin(), range.end(), greater{}, + deque>{begin(additional_data), end(additional_data)}, custom_allocator{}); #endif // !_HAS_CXX17 assert(pq7.size() == size(some_data) + size(additional_data)); result = 0; From 9a7e78121d81423c5586465449a301f0e9f433d9 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Thu, 12 Aug 2021 19:45:12 -0700 Subject: [PATCH 12/14] Rename variables, part 1: [pq2, pq7] to [xy3, xy8]. --- .../P1425R4_queue_stack_constructors/test.cpp | 84 +++++++++---------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/tests/std/tests/P1425R4_queue_stack_constructors/test.cpp b/tests/std/tests/P1425R4_queue_stack_constructors/test.cpp index 39399bc1f05..1647bed08b2 100644 --- a/tests/std/tests/P1425R4_queue_stack_constructors/test.cpp +++ b/tests/std/tests/P1425R4_queue_stack_constructors/test.cpp @@ -103,90 +103,90 @@ void test_container() { } #if _HAS_CXX17 - priority_queue pq2(range.begin(), range.end(), custom_allocator{}); - static_assert(is_same_v>, less>>); + priority_queue xy3(range.begin(), range.end(), custom_allocator{}); + static_assert(is_same_v>, less>>); #else // ^^^ _HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv - priority_queue>, less> pq2( + priority_queue>, less> xy3( range.begin(), range.end(), custom_allocator{}); #endif // !_HAS_CXX17 - assert(pq2.size() == size(some_data)); + assert(xy3.size() == size(some_data)); result = 5; - while (!pq2.empty()) { - assert(pq2.top() == result--); - pq2.pop(); + while (!xy3.empty()) { + assert(xy3.top() == result--); + xy3.pop(); } #if _HAS_CXX17 - priority_queue pq3(range.begin(), range.end(), greater{}, custom_allocator{}); - static_assert(is_same_v>, greater>>); + priority_queue xy4(range.begin(), range.end(), greater{}, custom_allocator{}); + static_assert(is_same_v>, greater>>); #else // ^^^ _HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv - priority_queue>, greater> pq3( + priority_queue>, greater> xy4( range.begin(), range.end(), greater{}, custom_allocator{}); #endif // !_HAS_CXX17 - assert(pq3.size() == size(some_data)); + assert(xy4.size() == size(some_data)); result = 0; - while (!pq3.empty()) { - assert(pq3.top() == result++); - pq3.pop(); + while (!xy4.empty()) { + assert(xy4.top() == result++); + xy4.pop(); } deque cont(begin(additional_data), end(additional_data)); #if _HAS_CXX17 - priority_queue pq4(range.begin(), range.end(), greater{}, cont); - static_assert(is_same_v, greater>>); + priority_queue xy5(range.begin(), range.end(), greater{}, cont); + static_assert(is_same_v, greater>>); #else // ^^^ _HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv - priority_queue, greater> pq4(range.begin(), range.end(), greater{}, cont); + priority_queue, greater> xy5(range.begin(), range.end(), greater{}, cont); #endif // !_HAS_CXX17 - assert(pq4.size() == size(some_data) + size(additional_data)); + assert(xy5.size() == size(some_data) + size(additional_data)); result = 0; - while (!pq4.empty()) { - assert(pq4.top() == result++); - pq4.pop(); + while (!xy5.empty()) { + assert(xy5.top() == result++); + xy5.pop(); } #if _HAS_CXX17 - priority_queue pq5( + priority_queue xy6( range.begin(), range.end(), greater{}, deque{begin(additional_data), end(additional_data)}); - static_assert(is_same_v, greater>>); + static_assert(is_same_v, greater>>); #else // ^^^ _HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv - priority_queue, greater> pq5( + priority_queue, greater> xy6( range.begin(), range.end(), greater{}, deque{begin(additional_data), end(additional_data)}); #endif // !_HAS_CXX17 - assert(pq5.size() == size(some_data) + size(additional_data)); + assert(xy6.size() == size(some_data) + size(additional_data)); result = 0; - while (!pq5.empty()) { - assert(pq5.top() == result++); - pq5.pop(); + while (!xy6.empty()) { + assert(xy6.top() == result++); + xy6.pop(); } deque> cont2(begin(additional_data), end(additional_data), custom_allocator{}); #if _HAS_CXX17 - priority_queue pq6(range.begin(), range.end(), greater{}, cont2, custom_allocator{}); - static_assert(is_same_v>, greater>>); + priority_queue xy7(range.begin(), range.end(), greater{}, cont2, custom_allocator{}); + static_assert(is_same_v>, greater>>); #else // ^^^ _HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv - priority_queue>, greater> pq6( + priority_queue>, greater> xy7( range.begin(), range.end(), greater{}, cont2, custom_allocator{}); #endif // !_HAS_CXX17 - assert(pq6.size() == size(some_data) + size(additional_data)); + assert(xy7.size() == size(some_data) + size(additional_data)); result = 0; - while (!pq6.empty()) { - assert(pq6.top() == result++); - pq6.pop(); + while (!xy7.empty()) { + assert(xy7.top() == result++); + xy7.pop(); } #if _HAS_CXX17 - priority_queue pq7(range.begin(), range.end(), greater{}, + priority_queue xy8(range.begin(), range.end(), greater{}, deque>{begin(additional_data), end(additional_data)}, custom_allocator{}); - static_assert(is_same_v>, greater>>); + static_assert(is_same_v>, greater>>); #else // ^^^ _HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv - priority_queue>, greater> pq7(range.begin(), range.end(), greater{}, + priority_queue>, greater> xy8(range.begin(), range.end(), greater{}, deque>{begin(additional_data), end(additional_data)}, custom_allocator{}); #endif // !_HAS_CXX17 - assert(pq7.size() == size(some_data) + size(additional_data)); + assert(xy8.size() == size(some_data) + size(additional_data)); result = 0; - while (!pq7.empty()) { - assert(pq7.top() == result++); - pq7.pop(); + while (!xy8.empty()) { + assert(xy8.top() == result++); + xy8.pop(); } } From 24af420bcb768a667adeea65d8e9bf234e4783cc Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Thu, 12 Aug 2021 19:46:47 -0700 Subject: [PATCH 13/14] Rename variables, part 2: [xy3, xy8] to [pq3, pq8]. --- .../P1425R4_queue_stack_constructors/test.cpp | 84 +++++++++---------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/tests/std/tests/P1425R4_queue_stack_constructors/test.cpp b/tests/std/tests/P1425R4_queue_stack_constructors/test.cpp index 1647bed08b2..ae2c135da35 100644 --- a/tests/std/tests/P1425R4_queue_stack_constructors/test.cpp +++ b/tests/std/tests/P1425R4_queue_stack_constructors/test.cpp @@ -103,90 +103,90 @@ void test_container() { } #if _HAS_CXX17 - priority_queue xy3(range.begin(), range.end(), custom_allocator{}); - static_assert(is_same_v>, less>>); + priority_queue pq3(range.begin(), range.end(), custom_allocator{}); + static_assert(is_same_v>, less>>); #else // ^^^ _HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv - priority_queue>, less> xy3( + priority_queue>, less> pq3( range.begin(), range.end(), custom_allocator{}); #endif // !_HAS_CXX17 - assert(xy3.size() == size(some_data)); + assert(pq3.size() == size(some_data)); result = 5; - while (!xy3.empty()) { - assert(xy3.top() == result--); - xy3.pop(); + while (!pq3.empty()) { + assert(pq3.top() == result--); + pq3.pop(); } #if _HAS_CXX17 - priority_queue xy4(range.begin(), range.end(), greater{}, custom_allocator{}); - static_assert(is_same_v>, greater>>); + priority_queue pq4(range.begin(), range.end(), greater{}, custom_allocator{}); + static_assert(is_same_v>, greater>>); #else // ^^^ _HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv - priority_queue>, greater> xy4( + priority_queue>, greater> pq4( range.begin(), range.end(), greater{}, custom_allocator{}); #endif // !_HAS_CXX17 - assert(xy4.size() == size(some_data)); + assert(pq4.size() == size(some_data)); result = 0; - while (!xy4.empty()) { - assert(xy4.top() == result++); - xy4.pop(); + while (!pq4.empty()) { + assert(pq4.top() == result++); + pq4.pop(); } deque cont(begin(additional_data), end(additional_data)); #if _HAS_CXX17 - priority_queue xy5(range.begin(), range.end(), greater{}, cont); - static_assert(is_same_v, greater>>); + priority_queue pq5(range.begin(), range.end(), greater{}, cont); + static_assert(is_same_v, greater>>); #else // ^^^ _HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv - priority_queue, greater> xy5(range.begin(), range.end(), greater{}, cont); + priority_queue, greater> pq5(range.begin(), range.end(), greater{}, cont); #endif // !_HAS_CXX17 - assert(xy5.size() == size(some_data) + size(additional_data)); + assert(pq5.size() == size(some_data) + size(additional_data)); result = 0; - while (!xy5.empty()) { - assert(xy5.top() == result++); - xy5.pop(); + while (!pq5.empty()) { + assert(pq5.top() == result++); + pq5.pop(); } #if _HAS_CXX17 - priority_queue xy6( + priority_queue pq6( range.begin(), range.end(), greater{}, deque{begin(additional_data), end(additional_data)}); - static_assert(is_same_v, greater>>); + static_assert(is_same_v, greater>>); #else // ^^^ _HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv - priority_queue, greater> xy6( + priority_queue, greater> pq6( range.begin(), range.end(), greater{}, deque{begin(additional_data), end(additional_data)}); #endif // !_HAS_CXX17 - assert(xy6.size() == size(some_data) + size(additional_data)); + assert(pq6.size() == size(some_data) + size(additional_data)); result = 0; - while (!xy6.empty()) { - assert(xy6.top() == result++); - xy6.pop(); + while (!pq6.empty()) { + assert(pq6.top() == result++); + pq6.pop(); } deque> cont2(begin(additional_data), end(additional_data), custom_allocator{}); #if _HAS_CXX17 - priority_queue xy7(range.begin(), range.end(), greater{}, cont2, custom_allocator{}); - static_assert(is_same_v>, greater>>); + priority_queue pq7(range.begin(), range.end(), greater{}, cont2, custom_allocator{}); + static_assert(is_same_v>, greater>>); #else // ^^^ _HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv - priority_queue>, greater> xy7( + priority_queue>, greater> pq7( range.begin(), range.end(), greater{}, cont2, custom_allocator{}); #endif // !_HAS_CXX17 - assert(xy7.size() == size(some_data) + size(additional_data)); + assert(pq7.size() == size(some_data) + size(additional_data)); result = 0; - while (!xy7.empty()) { - assert(xy7.top() == result++); - xy7.pop(); + while (!pq7.empty()) { + assert(pq7.top() == result++); + pq7.pop(); } #if _HAS_CXX17 - priority_queue xy8(range.begin(), range.end(), greater{}, + priority_queue pq8(range.begin(), range.end(), greater{}, deque>{begin(additional_data), end(additional_data)}, custom_allocator{}); - static_assert(is_same_v>, greater>>); + static_assert(is_same_v>, greater>>); #else // ^^^ _HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv - priority_queue>, greater> xy8(range.begin(), range.end(), greater{}, + priority_queue>, greater> pq8(range.begin(), range.end(), greater{}, deque>{begin(additional_data), end(additional_data)}, custom_allocator{}); #endif // !_HAS_CXX17 - assert(xy8.size() == size(some_data) + size(additional_data)); + assert(pq8.size() == size(some_data) + size(additional_data)); result = 0; - while (!xy8.empty()) { - assert(xy8.top() == result++); - xy8.pop(); + while (!pq8.empty()) { + assert(pq8.top() == result++); + pq8.pop(); } } From 6473d6d6056587e0d179a9a70cdb9ee18890ee86 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Thu, 12 Aug 2021 19:51:01 -0700 Subject: [PATCH 14/14] Test `priority_queue(InIt, InIt, const Compare&)`. --- .../tests/P1425R4_queue_stack_constructors/test.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/std/tests/P1425R4_queue_stack_constructors/test.cpp b/tests/std/tests/P1425R4_queue_stack_constructors/test.cpp index ae2c135da35..b2588665e63 100644 --- a/tests/std/tests/P1425R4_queue_stack_constructors/test.cpp +++ b/tests/std/tests/P1425R4_queue_stack_constructors/test.cpp @@ -102,6 +102,19 @@ void test_container() { pq1.pop(); } +#if _HAS_CXX17 + priority_queue pq2(range.begin(), range.end(), greater{}); + static_assert(is_same_v, greater>>); +#else // ^^^ _HAS_CXX17 ^^^ / vvv !_HAS_CXX17 vvv + priority_queue, greater> pq2(range.begin(), range.end(), greater{}); +#endif // !_HAS_CXX17 + assert(pq2.size() == size(some_data)); + result = 0; + while (!pq2.empty()) { + assert(pq2.top() == result++); + pq2.pop(); + } + #if _HAS_CXX17 priority_queue pq3(range.begin(), range.end(), custom_allocator{}); static_assert(is_same_v>, less>>);