From 4c357b6d6d2ba17263acf7a634c2d8b551323ed6 Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Wed, 1 Jul 2020 13:49:35 +0200 Subject: [PATCH 1/9] Remove invalid overload of ranges::copy_n --- stl/inc/algorithm | 6 --- .../tests/P0896R4_ranges_alg_copy_n/test.cpp | 46 +++++++++---------- 2 files changed, 21 insertions(+), 31 deletions(-) diff --git a/stl/inc/algorithm b/stl/inc/algorithm index 59db8eb1959..22bbc8f20b5 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -1557,12 +1557,6 @@ namespace ranges { _Seek_wrapped(_First, _STD move(_UFirst)); return {_STD move(_First), _STD move(_Result)}; } - - template - requires indirectly_copyable, _Out> - constexpr copy_n_result, _Out> operator()(_Rng&& _Range, _Out _Result) const { - return (*this)(_RANGES begin(_Range), _RANGES end(_Range), _STD move(_Result)); - } // clang-format on }; diff --git a/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp index 590df780886..05a492a37c2 100644 --- a/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp @@ -9,34 +9,30 @@ #include -constexpr void smoke_test() { - using ranges::copy_n, ranges::copy_n_result, ranges::iterator_t; - using std::same_as; +using ranges::copy_n, ranges::copy_n_result, ranges::iterator_t; +using std::same_as; - // Validate that copy_n_result aliases in_out_result - STATIC_ASSERT(same_as, ranges::in_out_result>); - - int const input[] = {13, 42, 1729}; - int output[] = {-1, -1, -1}; - basic_borrowed_range wrapped_input{input}; - auto result = copy_n(wrapped_input.begin(), ranges::distance(input), basic_borrowed_range{output}.begin()); - STATIC_ASSERT(same_as>, iterator_t>>>); - assert(result.in == wrapped_input.end()); - assert(result.out == basic_borrowed_range{output}.end()); - assert(ranges::equal(output, input)); -} - -int main() { - STATIC_ASSERT((smoke_test(), true)); - smoke_test(); -} +// Validate that copy_n_result aliases in_out_result +STATIC_ASSERT(same_as, ranges::in_out_result>); struct instantiator { - template - static void call(In in = {}, std::iter_difference_t const count = 42, Out out = {}) { - (void) ranges::copy_n(std::move(in), count, std::move(out)); + static constexpr int input[3] = {13, 42, 1729}; + template + static constexpr void call() { + int output[3] = {-1, -1, -1}; + auto result = copy_n(In{input}, ranges::distance(input), Write{output}); + STATIC_ASSERT(same_as>); + if constexpr (std::equality_comparable) { + assert(result.in == In{input + 3}); + } + if constexpr (std::equality_comparable) { + assert(result.out == Write{output + 3}); + } + assert(ranges::equal(output, input)); } }; -template void test_read_write(); +int main() { + STATIC_ASSERT((test_counted_write(), true)); + test_counted_write(); +} From 86a1e44b103e13442a9eb8ae1977305e87b1730f Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Wed, 1 Jul 2020 19:50:32 +0200 Subject: [PATCH 2/9] Update tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp Co-authored-by: Casey Carter --- tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp index 05a492a37c2..b35c26d5b5e 100644 --- a/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp @@ -22,9 +22,7 @@ struct instantiator { int output[3] = {-1, -1, -1}; auto result = copy_n(In{input}, ranges::distance(input), Write{output}); STATIC_ASSERT(same_as>); - if constexpr (std::equality_comparable) { - assert(result.in == In{input + 3}); - } + assert(result.in.base() == input + 3); if constexpr (std::equality_comparable) { assert(result.out == Write{output + 3}); } From b141537d5cef1c6ebccdd115887c7e4b18996fd0 Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Wed, 1 Jul 2020 19:50:41 +0200 Subject: [PATCH 3/9] Update tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp Co-authored-by: Casey Carter --- tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp index b35c26d5b5e..466f5f05bf1 100644 --- a/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp @@ -23,9 +23,7 @@ struct instantiator { auto result = copy_n(In{input}, ranges::distance(input), Write{output}); STATIC_ASSERT(same_as>); assert(result.in.base() == input + 3); - if constexpr (std::equality_comparable) { - assert(result.out == Write{output + 3}); - } + assert(result.out.base() == output + 3); assert(ranges::equal(output, input)); } }; From c88fdd99231b336fb18598606c134d43d077457f Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Wed, 1 Jul 2020 23:12:23 +0200 Subject: [PATCH 4/9] more reviews --- tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp index 466f5f05bf1..071275eee11 100644 --- a/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp @@ -9,8 +9,9 @@ #include +using namespace std; +using same_as; using ranges::copy_n, ranges::copy_n_result, ranges::iterator_t; -using std::same_as; // Validate that copy_n_result aliases in_out_result STATIC_ASSERT(same_as, ranges::in_out_result>); @@ -29,6 +30,6 @@ struct instantiator { }; int main() { - STATIC_ASSERT((test_counted_write(), true)); - test_counted_write(); + STATIC_ASSERT((test_counted_write(), true)); + test_counted_write(); } From 6578235d2f0642ce38f20333cc1e3b88fa6dddc7 Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Thu, 2 Jul 2020 14:22:44 +0200 Subject: [PATCH 5/9] Prepare for coming machinery --- .../tests/P0896R4_ranges_alg_copy_n/test.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp index 071275eee11..0e2ff9c5d3d 100644 --- a/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp @@ -10,21 +10,22 @@ #include using namespace std; -using same_as; -using ranges::copy_n, ranges::copy_n_result, ranges::iterator_t; // Validate that copy_n_result aliases in_out_result -STATIC_ASSERT(same_as, ranges::in_out_result>); +STATIC_ASSERT(same_as, ranges::in_out_result>); struct instantiator { static constexpr int input[3] = {13, 42, 1729}; - template + template static constexpr void call() { + using ranges::copy_n, ranges::copy_n_result, ranges::iterator_t; int output[3] = {-1, -1, -1}; - auto result = copy_n(In{input}, ranges::distance(input), Write{output}); - STATIC_ASSERT(same_as>); - assert(result.in.base() == input + 3); - assert(result.out.base() == output + 3); + Read wrapped_input{input}; + + auto result = copy_n(wrapped_input, ranges::distance(input), Write{output}); + STATIC_ASSERT(same_as>); + assert(result.in == wrapped_input.end()); + assert(result.out.peek() == output + 3); assert(ranges::equal(output, input)); } }; From f02731f4d2d6d13a9edcc197f2dac7effc40c4bb Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Fri, 3 Jul 2020 07:42:42 +0200 Subject: [PATCH 6/9] Review comments --- tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp index 0e2ff9c5d3d..be72e0fcab7 100644 --- a/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp @@ -16,14 +16,15 @@ STATIC_ASSERT(same_as, ranges::in_out_result< struct instantiator { static constexpr int input[3] = {13, 42, 1729}; - template + + template > Write> static constexpr void call() { using ranges::copy_n, ranges::copy_n_result, ranges::iterator_t; int output[3] = {-1, -1, -1}; Read wrapped_input{input}; - auto result = copy_n(wrapped_input, ranges::distance(input), Write{output}); - STATIC_ASSERT(same_as>); + auto result = copy_n(wrapped_input.begin(), ranges::distance(wrapped_input), Write{output}); + STATIC_ASSERT(same_as, Write>>); assert(result.in == wrapped_input.end()); assert(result.out.peek() == output + 3); assert(ranges::equal(output, input)); @@ -31,6 +32,6 @@ struct instantiator { }; int main() { - STATIC_ASSERT((test_counted_write(), true)); - test_counted_write(); + STATIC_ASSERT((test_read_write(), true)); + test_read_write(); } From cb0275e2f56ea7548a36f79aafca039c0da223b4 Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Fri, 3 Jul 2020 14:45:48 +0200 Subject: [PATCH 7/9] Use the input range... --- tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp index be72e0fcab7..64978bedf09 100644 --- a/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp @@ -32,6 +32,6 @@ struct instantiator { }; int main() { - STATIC_ASSERT((test_read_write(), true)); - test_read_write(); + STATIC_ASSERT((test_in_write(), true)); + test_in_write(); } From 1b1cc59cb03560a3d1f69abc0477da7cb34ac03f Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Fri, 3 Jul 2020 16:19:08 +0200 Subject: [PATCH 8/9] Use static length as for input ranges it crashes.... --- tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp index 64978bedf09..0f00b4d0967 100644 --- a/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp @@ -23,7 +23,7 @@ struct instantiator { int output[3] = {-1, -1, -1}; Read wrapped_input{input}; - auto result = copy_n(wrapped_input.begin(), ranges::distance(wrapped_input), Write{output}); + auto result = copy_n(wrapped_input.begin(), 3, Write{output}); STATIC_ASSERT(same_as, Write>>); assert(result.in == wrapped_input.end()); assert(result.out.peek() == output + 3); From 8c33735952401d31ab04869f704d23a6751d5196 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Wed, 8 Jul 2020 17:46:53 -0700 Subject: [PATCH 9/9] Update tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp East-`const` is best `const`, but `const`-west is de facto. =( --- tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp index 0f00b4d0967..b3c512888e2 100644 --- a/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_copy_n/test.cpp @@ -32,6 +32,6 @@ struct instantiator { }; int main() { - STATIC_ASSERT((test_in_write(), true)); - test_in_write(); + STATIC_ASSERT((test_in_write(), true)); + test_in_write(); }