From 19c2a1583e722ba048bea6639f4486daedb43bdb Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Mon, 8 Jun 2020 15:15:12 -0400 Subject: [PATCH 01/37] added the move algorithm on line 1265 of algorithm and created a new folder with test --- stl/inc/algorithm | 39 +++++++++++++ tests/std/test.lst | 1 + .../std/tests/P0896R4_ranges_alg_move/env.lst | 4 ++ .../tests/P0896R4_ranges_alg_move/test.cpp | 55 +++++++++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 tests/std/tests/P0896R4_ranges_alg_move/env.lst create mode 100644 tests/std/tests/P0896R4_ranges_alg_move/test.cpp diff --git a/stl/inc/algorithm b/stl/inc/algorithm index b6a009c14d7..9ce194acd07 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -1263,6 +1263,43 @@ namespace ranges { } // namespace ranges #endif // __cpp_lib_concepts +#ifdef __cpp_lib_concepts + +namespace ranges { + // ALIAS TEMPLATE copy_result + template + using move_result = in_out_result<_In, _Out>; + + class _Move_fn : private _Not_quite_object { + public: + using _Not_quite_object::_Not_quite_object; + + template _Se, weakly_incrementable _Out> + requires indirectly_movable<_It, _Out> constexpr move_result<_It, _Out> operator()( + _It _First, _Se _Last, _Out _Result) const { + _Adl_verify_range(_First, _Last); + auto _UFirst = _Get_unwrapped(_STD move(_First)); + const auto _ULast = _Get_unwrapped(_STD move(_Last)); + for (; _UFirst != _ULast; ++_UFirst, (void) ++_Result) { + *_Result = _RANGES iter_move(_UFirst); + } + + _Seek_wrapped(_First, _STD move(_UFirst)); + return {_STD move(_UFirst), _STD move(_Result)}; + } + + template + requires indirectly_movable, _Out> constexpr move_result, _Out> + operator()(_Rng&& _Range, _Out _Result) const { + return (*this)(_RANGES begin(_Range), _RANGES end(_Range), _STD move(_Result)); + } + }; + + inline constexpr _Move_fn move{_Not_quite_object::_Construct_tag{}}; +} // namespace ranges +#endif // __cpp_lib_concepts + + // FUNCTION TEMPLATE partition_copy template _CONSTEXPR20 pair<_OutIt1, _OutIt2> partition_copy( @@ -5173,6 +5210,8 @@ _NODISCARD constexpr const _Ty& clamp(const _Ty& _Val, const _Ty& _Min_val, cons } #endif // _HAS_CXX17 + + _STD_END #pragma pop_macro("new") _STL_RESTORE_CLANG_WARNINGS diff --git a/tests/std/test.lst b/tests/std/test.lst index 08cc1aec9f6..1ac2abf2080 100644 --- a/tests/std/test.lst +++ b/tests/std/test.lst @@ -249,6 +249,7 @@ tests\P0896R4_ranges_alg_find_if_not tests\P0896R4_ranges_alg_for_each tests\P0896R4_ranges_alg_for_each_n tests\P0896R4_ranges_alg_mismatch +tests\P0896R4_ranges_alg_move tests\P0896R4_ranges_alg_none_of tests\P0896R4_ranges_iterator_machinery tests\P0896R4_ranges_range_machinery diff --git a/tests/std/tests/P0896R4_ranges_alg_move/env.lst b/tests/std/tests/P0896R4_ranges_alg_move/env.lst new file mode 100644 index 00000000000..f3ccc8613c6 --- /dev/null +++ b/tests/std/tests/P0896R4_ranges_alg_move/env.lst @@ -0,0 +1,4 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +RUNALL_INCLUDE ..\concepts_matrix.lst diff --git a/tests/std/tests/P0896R4_ranges_alg_move/test.cpp b/tests/std/tests/P0896R4_ranges_alg_move/test.cpp new file mode 100644 index 00000000000..d32f8f8e2ef --- /dev/null +++ b/tests/std/tests/P0896R4_ranges_alg_move/test.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include +#include +#include + +void smoke_test() { + using ranges::move, ranges::move_result, ranges::iterator_t; + using std::same_as; + + // Validate that copy_result aliases in_out_result + STATIC_ASSERT(same_as, ranges::in_out_result>); + + // Validate dangling story + STATIC_ASSERT(same_as{}, static_cast(nullptr))), move_result>); + STATIC_ASSERT(same_as{}, static_cast(nullptr))), move_result>); + + int const input[] = {13, 53, 12435}; + { + int output[] = {-1, -1, -1}; + auto result = move(move_only_range{input}, move_only_range{output}.begin()); + STATIC_ASSERT(same_as>, iterator_t>>>); + std::cout << std::to_address(result.in.base()) << ' ' << std::to_address(move_only_range{input}.end().base()) << std::endl; + assert(result.in == move_only_range{input}.end()); + assert(result.out == move_only_range{output}.end()); + assert(ranges::equal(output, input)); + } + { + int output[] = {-1, -1, -1}; + move_only_range wrapped_input{input}; + auto result = move(wrapped_input.begin(), wrapped_input.end(), move_only_range{output}.begin()); + STATIC_ASSERT(same_as>, iterator_t>>>); + assert(result.in == wrapped_input.end()); + assert(result.out == move_only_range{output}.end()); + assert(ranges::equal(output, input)); + } +} + +int main() { + // STATIC_ASSERT((smoke_test(), true)); + smoke_test(); +} + +struct instantiator { + template + static void call(In&& in = {}, Out out = {}) { + (void) ranges::move(in, std::move(out)); + (void) ranges::move(ranges::begin(in), ranges::end(in), std::move(out)); // what is this + } +}; + +template void test_in_out(); \ No newline at end of file From 354e48bb550827785c20126223fa7907d1a82909 Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Mon, 8 Jun 2020 15:16:37 -0400 Subject: [PATCH 02/37] added cmake file --- cmake | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 cmake diff --git a/cmake b/cmake new file mode 100644 index 00000000000..e69de29bb2d From 09f6c9febfdd68905208dc60f07129141e8e91ed Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Mon, 8 Jun 2020 15:44:29 -0400 Subject: [PATCH 03/37] passing all tests for ranges move algorithm --- stl/inc/algorithm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/algorithm b/stl/inc/algorithm index 9ce194acd07..3ebd1b3b2d5 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -1285,7 +1285,7 @@ namespace ranges { } _Seek_wrapped(_First, _STD move(_UFirst)); - return {_STD move(_UFirst), _STD move(_Result)}; + return {_STD move(_First), _STD move(_Result)}; } template From 61375a9f778b037ea0f15f1b744db3aa1c6ddf8b Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Tue, 9 Jun 2020 14:34:09 -0400 Subject: [PATCH 04/37] updated move algo tests to check that we actually move elems, not just copy --- .../tests/P0896R4_ranges_alg_move/test.cpp | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/std/tests/P0896R4_ranges_alg_move/test.cpp b/tests/std/tests/P0896R4_ranges_alg_move/test.cpp index d32f8f8e2ef..51b70786662 100644 --- a/tests/std/tests/P0896R4_ranges_alg_move/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_move/test.cpp @@ -6,6 +6,17 @@ #include #include +struct int_wrapper { + int val = 10; + int_wrapper() = default; + int_wrapper(int x) : val{x} {} + int_wrapper(int_wrapper&& that) : val{std::exchange(that.val, -1)} {} + int_wrapper& operator=(int_wrapper&& that) { + val = std::exchange(that.val, -1); + return *this; + } +}; + void smoke_test() { using ranges::move, ranges::move_result, ranges::iterator_t; using std::same_as; @@ -37,6 +48,29 @@ void smoke_test() { assert(result.out == move_only_range{output}.end()); assert(ranges::equal(output, input)); } + { + int_wrapper input1[3]; + input1[0] = int_wrapper(13); + input1[1] = int_wrapper(55); + input1[2] = int_wrapper(1234); + int_wrapper expected_output[3]; + expected_output[0] = int_wrapper(13); + expected_output[1] = int_wrapper(55); + expected_output[2] = int_wrapper(1234); + int_wrapper actual_output[3]; + for (int i = 0; i < 3; i++) { + actual_output[i] = int_wrapper(-1); + } + move_only_range wrapped_input{input1}; + auto result = move(wrapped_input.begin(), wrapped_input.end(), move_only_range{actual_output}.begin()); + assert(result.in == wrapped_input.end()); + assert(result.out == move_only_range{actual_output}.end()); + for (int i = 0; i < 3; i++) { + assert(input1[i].val == -1); + assert(actual_output[i].val == expected_output[i].val); + } + } + } int main() { From 68640ed60549c88e2336b38eb94f7921386b213d Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Tue, 9 Jun 2020 15:02:28 -0400 Subject: [PATCH 05/37] enabled constexpr, cleaned up move algo test --- .../tests/P0896R4_ranges_alg_move/test.cpp | 32 +++++++------------ 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/tests/std/tests/P0896R4_ranges_alg_move/test.cpp b/tests/std/tests/P0896R4_ranges_alg_move/test.cpp index 51b70786662..a7641cc22b7 100644 --- a/tests/std/tests/P0896R4_ranges_alg_move/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_move/test.cpp @@ -8,20 +8,20 @@ struct int_wrapper { int val = 10; - int_wrapper() = default; - int_wrapper(int x) : val{x} {} - int_wrapper(int_wrapper&& that) : val{std::exchange(that.val, -1)} {} - int_wrapper& operator=(int_wrapper&& that) { + constexpr int_wrapper() = default; + constexpr int_wrapper(int x) : val{x} {} + constexpr int_wrapper(int_wrapper&& that) : val{std::exchange(that.val, -1)} {} + constexpr int_wrapper& operator=(int_wrapper&& that) { val = std::exchange(that.val, -1); return *this; } }; -void smoke_test() { +constexpr void smoke_test() { using ranges::move, ranges::move_result, ranges::iterator_t; using std::same_as; - // Validate that copy_result aliases in_out_result + // Validate that move_result aliases in_out_result STATIC_ASSERT(same_as, ranges::in_out_result>); // Validate dangling story @@ -34,7 +34,6 @@ void smoke_test() { auto result = move(move_only_range{input}, move_only_range{output}.begin()); STATIC_ASSERT(same_as>, iterator_t>>>); - std::cout << std::to_address(result.in.base()) << ' ' << std::to_address(move_only_range{input}.end().base()) << std::endl; assert(result.in == move_only_range{input}.end()); assert(result.out == move_only_range{output}.end()); assert(ranges::equal(output, input)); @@ -49,32 +48,23 @@ void smoke_test() { assert(ranges::equal(output, input)); } { - int_wrapper input1[3]; - input1[0] = int_wrapper(13); - input1[1] = int_wrapper(55); - input1[2] = int_wrapper(1234); - int_wrapper expected_output[3]; - expected_output[0] = int_wrapper(13); - expected_output[1] = int_wrapper(55); - expected_output[2] = int_wrapper(1234); - int_wrapper actual_output[3]; - for (int i = 0; i < 3; i++) { - actual_output[i] = int_wrapper(-1); - } + int_wrapper input1[3] = {13, 55, 1234}; + int expected_output[3] = {13, 55, 1234}; + int_wrapper actual_output[3] = {-1, -1, -1}; move_only_range wrapped_input{input1}; auto result = move(wrapped_input.begin(), wrapped_input.end(), move_only_range{actual_output}.begin()); assert(result.in == wrapped_input.end()); assert(result.out == move_only_range{actual_output}.end()); for (int i = 0; i < 3; i++) { assert(input1[i].val == -1); - assert(actual_output[i].val == expected_output[i].val); + assert(actual_output[i].val == expected_output[i]); } } } int main() { - // STATIC_ASSERT((smoke_test(), true)); + STATIC_ASSERT((smoke_test(), true)); smoke_test(); } From 52775525c8164b970827640dcd3b41b72e80df57 Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Tue, 9 Jun 2020 15:08:34 -0400 Subject: [PATCH 06/37] removed iostream unused header --- tests/std/tests/P0896R4_ranges_alg_move/test.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/std/tests/P0896R4_ranges_alg_move/test.cpp b/tests/std/tests/P0896R4_ranges_alg_move/test.cpp index a7641cc22b7..74bcac8cb5a 100644 --- a/tests/std/tests/P0896R4_ranges_alg_move/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_move/test.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include #include From 45fb14d92285012b6fb4d69101c6d6ef0fed09fa Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Wed, 10 Jun 2020 11:28:01 -0400 Subject: [PATCH 07/37] mainly updated formatting/comments based on feedback --- stl/inc/algorithm | 15 ++++++++------- tests/std/tests/P0896R4_ranges_alg_move/test.cpp | 9 ++++++--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/stl/inc/algorithm b/stl/inc/algorithm index 3ebd1b3b2d5..55a9f1e847f 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -1264,18 +1264,20 @@ namespace ranges { #endif // __cpp_lib_concepts #ifdef __cpp_lib_concepts - namespace ranges { - // ALIAS TEMPLATE copy_result + // ALIAS TEMPLATE move_result template using move_result = in_out_result<_In, _Out>; + // VARIABLE ranges::move class _Move_fn : private _Not_quite_object { public: using _Not_quite_object::_Not_quite_object; + // clang-format off template _Se, weakly_incrementable _Out> - requires indirectly_movable<_It, _Out> constexpr move_result<_It, _Out> operator()( + requires indirectly_movable<_It, _Out> + constexpr move_result<_It, _Out> operator()( _It _First, _Se _Last, _Out _Result) const { _Adl_verify_range(_First, _Last); auto _UFirst = _Get_unwrapped(_STD move(_First)); @@ -1289,17 +1291,18 @@ namespace ranges { } template - requires indirectly_movable, _Out> constexpr move_result, _Out> + requires indirectly_movable, _Out> + constexpr move_result, _Out> operator()(_Rng&& _Range, _Out _Result) const { return (*this)(_RANGES begin(_Range), _RANGES end(_Range), _STD move(_Result)); } + // clang-format on }; inline constexpr _Move_fn move{_Not_quite_object::_Construct_tag{}}; } // namespace ranges #endif // __cpp_lib_concepts - // FUNCTION TEMPLATE partition_copy template _CONSTEXPR20 pair<_OutIt1, _OutIt2> partition_copy( @@ -5210,8 +5213,6 @@ _NODISCARD constexpr const _Ty& clamp(const _Ty& _Val, const _Ty& _Min_val, cons } #endif // _HAS_CXX17 - - _STD_END #pragma pop_macro("new") _STL_RESTORE_CLANG_WARNINGS diff --git a/tests/std/tests/P0896R4_ranges_alg_move/test.cpp b/tests/std/tests/P0896R4_ranges_alg_move/test.cpp index 74bcac8cb5a..c5f7e4c841f 100644 --- a/tests/std/tests/P0896R4_ranges_alg_move/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_move/test.cpp @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + #include #include #include @@ -54,7 +57,7 @@ constexpr void smoke_test() { auto result = move(wrapped_input.begin(), wrapped_input.end(), move_only_range{actual_output}.begin()); assert(result.in == wrapped_input.end()); assert(result.out == move_only_range{actual_output}.end()); - for (int i = 0; i < 3; i++) { + for (int i = 0; i < 3; ++i) { assert(input1[i].val == -1); assert(actual_output[i].val == expected_output[i]); } @@ -71,8 +74,8 @@ struct instantiator { template static void call(In&& in = {}, Out out = {}) { (void) ranges::move(in, std::move(out)); - (void) ranges::move(ranges::begin(in), ranges::end(in), std::move(out)); // what is this + (void) ranges::move(ranges::begin(in), ranges::end(in), std::move(out)); } }; -template void test_in_out(); \ No newline at end of file +template void test_in_out(); From 80e349e50db39a1d47bc6774eeb4b4d560985b22 Mon Sep 17 00:00:00 2001 From: ahanamuk Date: Wed, 10 Jun 2020 11:33:47 -0400 Subject: [PATCH 08/37] Delete cmake --- cmake | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 cmake diff --git a/cmake b/cmake deleted file mode 100644 index e69de29bb2d..00000000000 From d4f91b0c81c0512e66fb9a5c0438f14e080e703a Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Thu, 11 Jun 2020 13:20:56 -0400 Subject: [PATCH 09/37] modified a test --- tests/std/tests/P0896R4_ranges_alg_move/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/std/tests/P0896R4_ranges_alg_move/test.cpp b/tests/std/tests/P0896R4_ranges_alg_move/test.cpp index c5f7e4c841f..c2f8925470f 100644 --- a/tests/std/tests/P0896R4_ranges_alg_move/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_move/test.cpp @@ -52,7 +52,7 @@ constexpr void smoke_test() { { int_wrapper input1[3] = {13, 55, 1234}; int expected_output[3] = {13, 55, 1234}; - int_wrapper actual_output[3] = {-1, -1, -1}; + int_wrapper actual_output[3] = {-2, -2, -2}; move_only_range wrapped_input{input1}; auto result = move(wrapped_input.begin(), wrapped_input.end(), move_only_range{actual_output}.begin()); assert(result.in == wrapped_input.end()); From c9f134f7b8bbc4bde4d4d87a42a6f493552b5968 Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Thu, 11 Jun 2020 13:35:17 -0400 Subject: [PATCH 10/37] initial fill algo --- stl/inc/algorithm | 35 +++++++++++++++++ tests/std/test.lst | 1 + .../std/tests/P0896R4_ranges_alg_fill/env.lst | 4 ++ .../tests/P0896R4_ranges_alg_fill/test.cpp | 39 +++++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 tests/std/tests/P0896R4_ranges_alg_fill/env.lst create mode 100644 tests/std/tests/P0896R4_ranges_alg_fill/test.cpp diff --git a/stl/inc/algorithm b/stl/inc/algorithm index 55a9f1e847f..943226e6ac2 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -2388,6 +2388,41 @@ _FwdIt2 replace_copy_if(_ExPo&&, _FwdIt1 _First, _FwdIt1 _Last, _FwdIt2 _Dest, _ } #endif // _HAS_CXX17 +#ifdef __cpp_lib_concepts +namespace ranges { + template + + // VARIABLE ranges::fill + class _Fill_fn : private _Not_quite_object { + public: + using _Not_quite_object::_Not_quite_object; + + // clang-format off + template _O, sentinel_for<_O> _S> + constexpr _O operator()(_O _First, _S _Last, const _T& _Value) const { + _Adl_verify_range(_First, _Last); + auto _UFirst = _Get_unwrapped(_STD move(_First)); + auto _ULast = _Get_unwrapped(_STD move(_Last)); + while (_UFirst != _ULast) { + *_UFirst = _Value; + ++_UFirst; + } + + _Seek_wrapped(_First, _STD move(_UFirst)); + return _First; + } + + template _Rng> + constexpr borrowed_iterator_t<_Rng> operator()(_Rng&& _Range, const _T& _Value) const { + return (*this)(_RANGES begin(_Range), _RANGES end(_Range), _Value) + } + // clang-format on + }; + + inline constexpr _Fill_fn fill{_Not_quite_object::_Construct_tag{}}; +} // namespace ranges +#endif // __cpp_lib_concepts + // FUNCTION TEMPLATE generate template _CONSTEXPR20 void generate(_FwdIt _First, _FwdIt _Last, _Fn _Func) { // replace [_First, _Last) with _Func() diff --git a/tests/std/test.lst b/tests/std/test.lst index 1ac2abf2080..d9ab9d6ee76 100644 --- a/tests/std/test.lst +++ b/tests/std/test.lst @@ -241,6 +241,7 @@ tests\P0896R4_ranges_alg_copy_n tests\P0896R4_ranges_alg_count tests\P0896R4_ranges_alg_count_if tests\P0896R4_ranges_alg_equal +tests\P0896R4_ranges_alg_fill tests\P0896R4_ranges_alg_find tests\P0896R4_ranges_alg_find_end tests\P0896R4_ranges_alg_find_first_of diff --git a/tests/std/tests/P0896R4_ranges_alg_fill/env.lst b/tests/std/tests/P0896R4_ranges_alg_fill/env.lst new file mode 100644 index 00000000000..f3ccc8613c6 --- /dev/null +++ b/tests/std/tests/P0896R4_ranges_alg_fill/env.lst @@ -0,0 +1,4 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +RUNALL_INCLUDE ..\concepts_matrix.lst diff --git a/tests/std/tests/P0896R4_ranges_alg_fill/test.cpp b/tests/std/tests/P0896R4_ranges_alg_fill/test.cpp new file mode 100644 index 00000000000..e65197dd78b --- /dev/null +++ b/tests/std/tests/P0896R4_ranges_alg_fill/test.cpp @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include +#include +#include +#include +#include +#include + +constexpr void smoke_test() { + using ranges::fill, ranges::iterator_t; + using std::same_as; + + int output[] = {13, 42, 1367}; + { + const int value = 7; + auto result = fill(output.begin(), output.end(), value); + for (int i = 0; i < 3; ++i) { + assert(output[i] == 7); + } + assert(result == output.end()); + } +} + +int main() { + // STATIC_ASSERT((smoke_test(), true)); + smoke_test(); +} + +struct instantiator { + template + static void call(In&& in = {}) { + (void) ranges::fill(in, SOMETHING); + (void) ranges::fill(ranges::begin(in), ranges::end(in), SOMETHING); + } +}; + +template void test_in_out(); From 93ff9476be4433c53955dacfe5585ea25d1e13f2 Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Thu, 11 Jun 2020 14:52:24 -0400 Subject: [PATCH 11/37] Passing all fill tests --- stl/inc/algorithm | 4 +-- tests/std/include/range_algorithm_support.hpp | 27 ++++++++++++++++++- .../tests/P0896R4_ranges_alg_fill/test.cpp | 16 +++++------ 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/stl/inc/algorithm b/stl/inc/algorithm index 943226e6ac2..7d97d806ff1 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -2390,7 +2390,7 @@ _FwdIt2 replace_copy_if(_ExPo&&, _FwdIt1 _First, _FwdIt1 _Last, _FwdIt2 _Dest, _ #ifdef __cpp_lib_concepts namespace ranges { - template + // template // VARIABLE ranges::fill class _Fill_fn : private _Not_quite_object { @@ -2414,7 +2414,7 @@ namespace ranges { template _Rng> constexpr borrowed_iterator_t<_Rng> operator()(_Rng&& _Range, const _T& _Value) const { - return (*this)(_RANGES begin(_Range), _RANGES end(_Range), _Value) + return (*this)(_RANGES begin(_Range), _RANGES end(_Range), _Value); } // clang-format on }; diff --git a/tests/std/include/range_algorithm_support.hpp b/tests/std/include/range_algorithm_support.hpp index cc0d77625ae..27a852a3ff6 100644 --- a/tests/std/include/range_algorithm_support.hpp +++ b/tests/std/include/range_algorithm_support.hpp @@ -488,6 +488,31 @@ struct with_input_ranges { } }; +template +struct with_output_ranges { + template + static void call() { + Continuation::template call>(); + Continuation::template call>(); + + Continuation::template call>(); + Continuation::template call>(); + Continuation::template call>(); + Continuation::template call>(); + + Continuation::template call>(); + Continuation::template call>(); + Continuation::template call>(); + Continuation::template call>(); + + Continuation::template call>(); + Continuation::template call>(); + + Continuation::template call>(); + Continuation::template call>(); + } +}; + template struct with_forward_ranges { template @@ -534,7 +559,7 @@ struct with_difference { template void test_out() { - with_output_iterators::call(); + with_output_ranges::call(); } template diff --git a/tests/std/tests/P0896R4_ranges_alg_fill/test.cpp b/tests/std/tests/P0896R4_ranges_alg_fill/test.cpp index e65197dd78b..009b600bc8c 100644 --- a/tests/std/tests/P0896R4_ranges_alg_fill/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_fill/test.cpp @@ -15,25 +15,25 @@ constexpr void smoke_test() { int output[] = {13, 42, 1367}; { const int value = 7; - auto result = fill(output.begin(), output.end(), value); + auto result = fill(std::begin(output), std::end(output), value); for (int i = 0; i < 3; ++i) { assert(output[i] == 7); } - assert(result == output.end()); + assert(result == std::end(output)); } } int main() { - // STATIC_ASSERT((smoke_test(), true)); + STATIC_ASSERT((smoke_test(), true)); smoke_test(); } struct instantiator { - template - static void call(In&& in = {}) { - (void) ranges::fill(in, SOMETHING); - (void) ranges::fill(ranges::begin(in), ranges::end(in), SOMETHING); + template + static void call(Out&& out = {}) { + (void) ranges::fill(out, 42); + (void) ranges::fill(ranges::begin(out), ranges::end(out), 42); } }; -template void test_in_out(); +template void test_out(); From be947f1103785549012bb328b2d06cbd1d0e038a Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Thu, 11 Jun 2020 14:59:07 -0400 Subject: [PATCH 12/37] added a test case --- .../std/tests/P0896R4_ranges_alg_fill/test.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/std/tests/P0896R4_ranges_alg_fill/test.cpp b/tests/std/tests/P0896R4_ranges_alg_fill/test.cpp index 009b600bc8c..a9021bcb1fe 100644 --- a/tests/std/tests/P0896R4_ranges_alg_fill/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_fill/test.cpp @@ -12,15 +12,25 @@ constexpr void smoke_test() { using ranges::fill, ranges::iterator_t; using std::same_as; - int output[] = {13, 42, 1367}; + int output1[] = {13, 42, 1367}; + int output2[] = {13, 42, 1367}; { const int value = 7; - auto result = fill(std::begin(output), std::end(output), value); + auto result = fill(std::begin(output1), std::end(output1), value); for (int i = 0; i < 3; ++i) { - assert(output[i] == 7); + assert(output1[i] == 7); } - assert(result == std::end(output)); + assert(result == std::end(output1)); } + { + const int value = 13; + auto result = fill(output2, value); + for (int i = 0; i < 3; ++i) { + assert(output2[i] == 13); + } + assert(result == std::end(output2)); + } + } int main() { From 5cb7bfcf72a72149a916d18a3078ea78a99360c8 Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Fri, 12 Jun 2020 11:27:00 -0400 Subject: [PATCH 13/37] minor changes/formatting updates to move --- stl/inc/algorithm | 5 +---- tests/std/tests/P0896R4_ranges_alg_move/test.cpp | 8 +++++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/stl/inc/algorithm b/stl/inc/algorithm index 7d97d806ff1..d9815fc2dc0 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -1261,9 +1261,7 @@ namespace ranges { inline constexpr _Copy_if_fn copy_if{_Not_quite_object::_Construct_tag{}}; } // namespace ranges -#endif // __cpp_lib_concepts -#ifdef __cpp_lib_concepts namespace ranges { // ALIAS TEMPLATE move_result template @@ -1277,8 +1275,7 @@ namespace ranges { // clang-format off template _Se, weakly_incrementable _Out> requires indirectly_movable<_It, _Out> - constexpr move_result<_It, _Out> operator()( - _It _First, _Se _Last, _Out _Result) const { + constexpr move_result<_It, _Out> operator()(_It _First, _Se _Last, _Out _Result) const { _Adl_verify_range(_First, _Last); auto _UFirst = _Get_unwrapped(_STD move(_First)); const auto _ULast = _Get_unwrapped(_STD move(_Last)); diff --git a/tests/std/tests/P0896R4_ranges_alg_move/test.cpp b/tests/std/tests/P0896R4_ranges_alg_move/test.cpp index c2f8925470f..0e80d08c8de 100644 --- a/tests/std/tests/P0896R4_ranges_alg_move/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_move/test.cpp @@ -27,8 +27,10 @@ constexpr void smoke_test() { STATIC_ASSERT(same_as, ranges::in_out_result>); // Validate dangling story - STATIC_ASSERT(same_as{}, static_cast(nullptr))), move_result>); - STATIC_ASSERT(same_as{}, static_cast(nullptr))), move_result>); + STATIC_ASSERT(same_as{}, static_cast(nullptr))), + move_result>); + STATIC_ASSERT(same_as{}, static_cast(nullptr))), + move_result>); int const input[] = {13, 53, 12435}; { @@ -51,7 +53,7 @@ constexpr void smoke_test() { } { int_wrapper input1[3] = {13, 55, 1234}; - int expected_output[3] = {13, 55, 1234}; + int const expected_output[3] = {13, 55, 1234}; int_wrapper actual_output[3] = {-2, -2, -2}; move_only_range wrapped_input{input1}; auto result = move(wrapped_input.begin(), wrapped_input.end(), move_only_range{actual_output}.begin()); From 91700775b09d1a42a7ab3e81699b6f5cc4b81a29 Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Fri, 12 Jun 2020 13:09:29 -0400 Subject: [PATCH 14/37] updated clang formatting --- .../tests/P0896R4_ranges_alg_fill/test.cpp | 7 +++--- .../tests/P0896R4_ranges_alg_move/test.cpp | 25 +++++++++---------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/tests/std/tests/P0896R4_ranges_alg_fill/test.cpp b/tests/std/tests/P0896R4_ranges_alg_fill/test.cpp index a9021bcb1fe..d8290a3071f 100644 --- a/tests/std/tests/P0896R4_ranges_alg_fill/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_fill/test.cpp @@ -4,9 +4,9 @@ #include #include #include +#include #include #include -#include constexpr void smoke_test() { using ranges::fill, ranges::iterator_t; @@ -16,7 +16,7 @@ constexpr void smoke_test() { int output2[] = {13, 42, 1367}; { const int value = 7; - auto result = fill(std::begin(output1), std::end(output1), value); + auto result = fill(std::begin(output1), std::end(output1), value); for (int i = 0; i < 3; ++i) { assert(output1[i] == 7); } @@ -24,13 +24,12 @@ constexpr void smoke_test() { } { const int value = 13; - auto result = fill(output2, value); + auto result = fill(output2, value); for (int i = 0; i < 3; ++i) { assert(output2[i] == 13); } assert(result == std::end(output2)); } - } int main() { diff --git a/tests/std/tests/P0896R4_ranges_alg_move/test.cpp b/tests/std/tests/P0896R4_ranges_alg_move/test.cpp index 0e80d08c8de..fcb5f71d3c7 100644 --- a/tests/std/tests/P0896R4_ranges_alg_move/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_move/test.cpp @@ -4,12 +4,12 @@ #include #include #include +#include #include #include -#include struct int_wrapper { - int val = 10; + int val = 10; constexpr int_wrapper() = default; constexpr int_wrapper(int x) : val{x} {} constexpr int_wrapper(int_wrapper&& that) : val{std::exchange(that.val, -1)} {} @@ -27,16 +27,15 @@ constexpr void smoke_test() { STATIC_ASSERT(same_as, ranges::in_out_result>); // Validate dangling story - STATIC_ASSERT(same_as{}, static_cast(nullptr))), - move_result>); - STATIC_ASSERT(same_as{}, static_cast(nullptr))), - move_result>); + STATIC_ASSERT( + same_as{}, static_cast(nullptr))), move_result>); + STATIC_ASSERT(same_as{}, static_cast(nullptr))), move_result>); int const input[] = {13, 53, 12435}; { int output[] = {-1, -1, -1}; - auto result = move(move_only_range{input}, move_only_range{output}.begin()); - STATIC_ASSERT(same_as>, iterator_t>>>); assert(result.in == move_only_range{input}.end()); assert(result.out == move_only_range{output}.end()); @@ -46,13 +45,14 @@ constexpr void smoke_test() { int output[] = {-1, -1, -1}; move_only_range wrapped_input{input}; auto result = move(wrapped_input.begin(), wrapped_input.end(), move_only_range{output}.begin()); - STATIC_ASSERT(same_as>, iterator_t>>>); + STATIC_ASSERT(same_as>, iterator_t>>>); assert(result.in == wrapped_input.end()); assert(result.out == move_only_range{output}.end()); assert(ranges::equal(output, input)); } { - int_wrapper input1[3] = {13, 55, 1234}; + int_wrapper input1[3] = {13, 55, 1234}; int const expected_output[3] = {13, 55, 1234}; int_wrapper actual_output[3] = {-2, -2, -2}; move_only_range wrapped_input{input1}; @@ -60,11 +60,10 @@ constexpr void smoke_test() { assert(result.in == wrapped_input.end()); assert(result.out == move_only_range{actual_output}.end()); for (int i = 0; i < 3; ++i) { - assert(input1[i].val == -1); - assert(actual_output[i].val == expected_output[i]); + assert(input1[i].val == -1); + assert(actual_output[i].val == expected_output[i]); } } - } int main() { From d4fbaac7c0bca476e79c23a10548e2aa630bc8c3 Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Thu, 11 Jun 2020 13:35:17 -0400 Subject: [PATCH 15/37] initial fill algo --- stl/inc/algorithm | 4 ++-- tests/std/tests/P0896R4_ranges_alg_fill/test.cpp | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/stl/inc/algorithm b/stl/inc/algorithm index d9815fc2dc0..d8c2cf9ed91 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -2387,7 +2387,7 @@ _FwdIt2 replace_copy_if(_ExPo&&, _FwdIt1 _First, _FwdIt1 _Last, _FwdIt2 _Dest, _ #ifdef __cpp_lib_concepts namespace ranges { - // template + template // VARIABLE ranges::fill class _Fill_fn : private _Not_quite_object { @@ -2411,7 +2411,7 @@ namespace ranges { template _Rng> constexpr borrowed_iterator_t<_Rng> operator()(_Rng&& _Range, const _T& _Value) const { - return (*this)(_RANGES begin(_Range), _RANGES end(_Range), _Value); + return (*this)(_RANGES begin(_Range), _RANGES end(_Range), _Value) } // clang-format on }; diff --git a/tests/std/tests/P0896R4_ranges_alg_fill/test.cpp b/tests/std/tests/P0896R4_ranges_alg_fill/test.cpp index d8290a3071f..7104e6987e4 100644 --- a/tests/std/tests/P0896R4_ranges_alg_fill/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_fill/test.cpp @@ -29,11 +29,20 @@ constexpr void smoke_test() { assert(output2[i] == 13); } assert(result == std::end(output2)); + int output[] = {13, 42, 1367}; + { + const int value = 7; + auto result = fill(output.begin(), output.end(), value); + for (int i = 0; i < 3; ++i) { + assert(output[i] == 7); + } + assert(result == output.end()); } } int main() { STATIC_ASSERT((smoke_test(), true)); + // STATIC_ASSERT((smoke_test(), true)); smoke_test(); } @@ -45,4 +54,4 @@ struct instantiator { } }; -template void test_out(); +template void test_in_out(); From 064684e4fb5a41dd0d9e62d4d46cdbea2b5909cc Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Tue, 16 Jun 2020 10:40:38 -0400 Subject: [PATCH 16/37] comitting untracked stuff --- stl/inc/algorithm | 79 ++++++++++++++++++++++++++++++++++++++++++++-- tests/std/test.lst | 2 ++ 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/stl/inc/algorithm b/stl/inc/algorithm index d8c2cf9ed91..af602140c89 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -2387,7 +2387,6 @@ _FwdIt2 replace_copy_if(_ExPo&&, _FwdIt1 _First, _FwdIt1 _Last, _FwdIt2 _Dest, _ #ifdef __cpp_lib_concepts namespace ranges { - template // VARIABLE ranges::fill class _Fill_fn : private _Not_quite_object { @@ -2411,12 +2410,88 @@ namespace ranges { template _Rng> constexpr borrowed_iterator_t<_Rng> operator()(_Rng&& _Range, const _T& _Value) const { - return (*this)(_RANGES begin(_Range), _RANGES end(_Range), _Value) + return (*this)(_RANGES begin(_Range), _RANGES end(_Range), _Value); } // clang-format on }; inline constexpr _Fill_fn fill{_Not_quite_object::_Construct_tag{}}; + + // VARIABLE ranges::fill_n + class _Fill_n_fn : private _Not_quite_object { + public: + using _Not_quite_object::_Not_quite_object; + + // clang-format off + template _O> + constexpr _O operator()(_O _First, iter_difference_t<_O> _Count, const _T& _Value) const { + auto _UFirst = _Get_unwrapped_n(_STD move(_First), _Count); + for (; _Count > 0; ++_UFirst, --_Count) { + *_UFirst = _Value; + } + + _Seek_wrapped(_First, _STD move(_UFirst)); + return _First; + } + // clang-format on + }; + + inline constexpr _Fill_n_fn fill_n{_Not_quite_object::_Construct_tag{}}; +} // namespace ranges +#endif // __cpp_lib_concepts + +#ifdef __cpp_lib_concepts +namespace ranges { + // VARIABLE ranges::generate + class _Generate_fn : private _Not_quite_object { + public: + using _Not_quite_object::_Not_quite_object; + + // clang-format off + template _S, copy_constructible _F> + requires invocable<_F&> && indirectly_writable<_O, invoke_result_t<_F&>> + constexpr _O operator()(_O _First, _S _Last, _F _Gen) const { + _Adl_verify_range(_First, _Last); + auto _UFirst = _Get_unwrapped(_First); + const auto _ULast = _Get_unwrapped(_Last); + for (; _UFirst != _ULast; ++_UFirst) { + *_UFirst = _Gen(); + } + + _Seek_wrapped(_First, _STD move(_UFirst)); + return _First; + } + + template + requires invocable<_F&> && output_range<_R, invoke_result_t<_F&>> + constexpr borrowed_iterator_t<_R> operator()(_R&& _Range, _F _Gen) const { + return (*this)(_RANGES begin(_Range), _RANGES end(_Range), _Gen); + } + // clang-format on + }; + + inline constexpr _Generate_fn generate{_Not_quite_object::_Construct_tag{}}; + + // VARIABLE ranges::generate_n + class _Generate_n_fn : private _Not_quite_object { + public: + using _Not_quite_object::_Not_quite_object; + + // clang-format off + template + requires invocable<_F&> && indirectly_writable<_O, invoke_result_t<_F&>> + constexpr _O operator()(_O _First, iter_difference_t<_O> _Count, _F _Gen) const { + auto _UFirst = _Get_unwrapped_n(_STD move(_First), _Count); // what if count is larger than num elems + for (; _Count > 0; ++_UFirst, --_Count) { + *_UFirst = _Gen(); + } + + _Seek_wrapped(_First, _STD move(_UFirst)); + return _First; + } + } + + inline constexpr _Generate_n_fn generate_n{_Not_quite_object::_Construct_tag{}}; } // namespace ranges #endif // __cpp_lib_concepts diff --git a/tests/std/test.lst b/tests/std/test.lst index d9ab9d6ee76..d5c04757a85 100644 --- a/tests/std/test.lst +++ b/tests/std/test.lst @@ -242,6 +242,7 @@ tests\P0896R4_ranges_alg_count tests\P0896R4_ranges_alg_count_if tests\P0896R4_ranges_alg_equal tests\P0896R4_ranges_alg_fill +tests\P0896R4_ranges_alg_fill_n tests\P0896R4_ranges_alg_find tests\P0896R4_ranges_alg_find_end tests\P0896R4_ranges_alg_find_first_of @@ -249,6 +250,7 @@ tests\P0896R4_ranges_alg_find_if tests\P0896R4_ranges_alg_find_if_not tests\P0896R4_ranges_alg_for_each tests\P0896R4_ranges_alg_for_each_n +tests\P0896R4_ranges_alg_generate tests\P0896R4_ranges_alg_mismatch tests\P0896R4_ranges_alg_move tests\P0896R4_ranges_alg_none_of From 91040f9237c11c28b6de559dc0c911fce8e2099b Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Tue, 16 Jun 2020 10:54:39 -0400 Subject: [PATCH 17/37] generate initial commit --- stl/inc/algorithm | 92 ------------------- tests/std/test.lst | 4 +- .../env.lst | 0 .../P0896R4_ranges_alg_generate/test.cpp | 46 ++++++++++ .../tests/P0896R4_ranges_alg_move/test.cpp | 82 ----------------- 5 files changed, 47 insertions(+), 177 deletions(-) rename tests/std/tests/{P0896R4_ranges_alg_move => P0896R4_ranges_alg_generate}/env.lst (100%) create mode 100644 tests/std/tests/P0896R4_ranges_alg_generate/test.cpp delete mode 100644 tests/std/tests/P0896R4_ranges_alg_move/test.cpp diff --git a/stl/inc/algorithm b/stl/inc/algorithm index af602140c89..2cbd1902647 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -1261,43 +1261,6 @@ namespace ranges { inline constexpr _Copy_if_fn copy_if{_Not_quite_object::_Construct_tag{}}; } // namespace ranges - -namespace ranges { - // ALIAS TEMPLATE move_result - template - using move_result = in_out_result<_In, _Out>; - - // VARIABLE ranges::move - class _Move_fn : private _Not_quite_object { - public: - using _Not_quite_object::_Not_quite_object; - - // clang-format off - template _Se, weakly_incrementable _Out> - requires indirectly_movable<_It, _Out> - constexpr move_result<_It, _Out> operator()(_It _First, _Se _Last, _Out _Result) const { - _Adl_verify_range(_First, _Last); - auto _UFirst = _Get_unwrapped(_STD move(_First)); - const auto _ULast = _Get_unwrapped(_STD move(_Last)); - for (; _UFirst != _ULast; ++_UFirst, (void) ++_Result) { - *_Result = _RANGES iter_move(_UFirst); - } - - _Seek_wrapped(_First, _STD move(_UFirst)); - return {_STD move(_First), _STD move(_Result)}; - } - - template - requires indirectly_movable, _Out> - constexpr move_result, _Out> - operator()(_Rng&& _Range, _Out _Result) const { - return (*this)(_RANGES begin(_Range), _RANGES end(_Range), _STD move(_Result)); - } - // clang-format on - }; - - inline constexpr _Move_fn move{_Not_quite_object::_Construct_tag{}}; -} // namespace ranges #endif // __cpp_lib_concepts // FUNCTION TEMPLATE partition_copy @@ -2385,61 +2348,6 @@ _FwdIt2 replace_copy_if(_ExPo&&, _FwdIt1 _First, _FwdIt1 _Last, _FwdIt2 _Dest, _ } #endif // _HAS_CXX17 -#ifdef __cpp_lib_concepts -namespace ranges { - - // VARIABLE ranges::fill - class _Fill_fn : private _Not_quite_object { - public: - using _Not_quite_object::_Not_quite_object; - - // clang-format off - template _O, sentinel_for<_O> _S> - constexpr _O operator()(_O _First, _S _Last, const _T& _Value) const { - _Adl_verify_range(_First, _Last); - auto _UFirst = _Get_unwrapped(_STD move(_First)); - auto _ULast = _Get_unwrapped(_STD move(_Last)); - while (_UFirst != _ULast) { - *_UFirst = _Value; - ++_UFirst; - } - - _Seek_wrapped(_First, _STD move(_UFirst)); - return _First; - } - - template _Rng> - constexpr borrowed_iterator_t<_Rng> operator()(_Rng&& _Range, const _T& _Value) const { - return (*this)(_RANGES begin(_Range), _RANGES end(_Range), _Value); - } - // clang-format on - }; - - inline constexpr _Fill_fn fill{_Not_quite_object::_Construct_tag{}}; - - // VARIABLE ranges::fill_n - class _Fill_n_fn : private _Not_quite_object { - public: - using _Not_quite_object::_Not_quite_object; - - // clang-format off - template _O> - constexpr _O operator()(_O _First, iter_difference_t<_O> _Count, const _T& _Value) const { - auto _UFirst = _Get_unwrapped_n(_STD move(_First), _Count); - for (; _Count > 0; ++_UFirst, --_Count) { - *_UFirst = _Value; - } - - _Seek_wrapped(_First, _STD move(_UFirst)); - return _First; - } - // clang-format on - }; - - inline constexpr _Fill_n_fn fill_n{_Not_quite_object::_Construct_tag{}}; -} // namespace ranges -#endif // __cpp_lib_concepts - #ifdef __cpp_lib_concepts namespace ranges { // VARIABLE ranges::generate diff --git a/tests/std/test.lst b/tests/std/test.lst index d5c04757a85..ccc92bc23b9 100644 --- a/tests/std/test.lst +++ b/tests/std/test.lst @@ -241,8 +241,6 @@ tests\P0896R4_ranges_alg_copy_n tests\P0896R4_ranges_alg_count tests\P0896R4_ranges_alg_count_if tests\P0896R4_ranges_alg_equal -tests\P0896R4_ranges_alg_fill -tests\P0896R4_ranges_alg_fill_n tests\P0896R4_ranges_alg_find tests\P0896R4_ranges_alg_find_end tests\P0896R4_ranges_alg_find_first_of @@ -251,8 +249,8 @@ tests\P0896R4_ranges_alg_find_if_not tests\P0896R4_ranges_alg_for_each tests\P0896R4_ranges_alg_for_each_n tests\P0896R4_ranges_alg_generate +tests\P0896R4_ranges_alg_generate_n tests\P0896R4_ranges_alg_mismatch -tests\P0896R4_ranges_alg_move tests\P0896R4_ranges_alg_none_of tests\P0896R4_ranges_iterator_machinery tests\P0896R4_ranges_range_machinery diff --git a/tests/std/tests/P0896R4_ranges_alg_move/env.lst b/tests/std/tests/P0896R4_ranges_alg_generate/env.lst similarity index 100% rename from tests/std/tests/P0896R4_ranges_alg_move/env.lst rename to tests/std/tests/P0896R4_ranges_alg_generate/env.lst diff --git a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp new file mode 100644 index 00000000000..8887c5ea90d --- /dev/null +++ b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +#include +#include +#include +#include +#include +#include + +constexpr void smoke_test() { + using ranges::generate, ranges::iterator_t; + using std::same_as; + + int output1[] = {13, 42, 1367}; + int output2[] = {13, 42, 1367}; + { + auto result = generate(std::begin(output1), std::end(output1), [](){return 7;}); + for (int i = 0; i < 3; ++i) { + assert(output1[i] == 7); + } + assert(result == std::end(output1)); + } + { + auto result = generate(output2, [](){return 13;}); + for (int i = 0; i < 3; ++i) { + assert(output2[i] == 13); + } + assert(result == std::end(output2)); + } +} + +int main() { + STATIC_ASSERT((smoke_test(), true)); + smoke_test(); +} + +struct instantiator { + template + static void call(Out&& out = {}) { + (void) ranges::generate(out, [](){return 13;}); + (void) ranges::generate(ranges::begin(out), ranges::end(out), [](){return 13;}); + } +}; + +template void test_out(); \ No newline at end of file diff --git a/tests/std/tests/P0896R4_ranges_alg_move/test.cpp b/tests/std/tests/P0896R4_ranges_alg_move/test.cpp deleted file mode 100644 index fcb5f71d3c7..00000000000 --- a/tests/std/tests/P0896R4_ranges_alg_move/test.cpp +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -#include -#include -#include -#include -#include -#include - -struct int_wrapper { - int val = 10; - constexpr int_wrapper() = default; - constexpr int_wrapper(int x) : val{x} {} - constexpr int_wrapper(int_wrapper&& that) : val{std::exchange(that.val, -1)} {} - constexpr int_wrapper& operator=(int_wrapper&& that) { - val = std::exchange(that.val, -1); - return *this; - } -}; - -constexpr void smoke_test() { - using ranges::move, ranges::move_result, ranges::iterator_t; - using std::same_as; - - // Validate that move_result aliases in_out_result - STATIC_ASSERT(same_as, ranges::in_out_result>); - - // Validate dangling story - STATIC_ASSERT( - same_as{}, static_cast(nullptr))), move_result>); - STATIC_ASSERT(same_as{}, static_cast(nullptr))), move_result>); - - int const input[] = {13, 53, 12435}; - { - int output[] = {-1, -1, -1}; - auto result = move(move_only_range{input}, move_only_range{output}.begin()); - STATIC_ASSERT(same_as>, iterator_t>>>); - assert(result.in == move_only_range{input}.end()); - assert(result.out == move_only_range{output}.end()); - assert(ranges::equal(output, input)); - } - { - int output[] = {-1, -1, -1}; - move_only_range wrapped_input{input}; - auto result = move(wrapped_input.begin(), wrapped_input.end(), move_only_range{output}.begin()); - STATIC_ASSERT(same_as>, iterator_t>>>); - assert(result.in == wrapped_input.end()); - assert(result.out == move_only_range{output}.end()); - assert(ranges::equal(output, input)); - } - { - int_wrapper input1[3] = {13, 55, 1234}; - int const expected_output[3] = {13, 55, 1234}; - int_wrapper actual_output[3] = {-2, -2, -2}; - move_only_range wrapped_input{input1}; - auto result = move(wrapped_input.begin(), wrapped_input.end(), move_only_range{actual_output}.begin()); - assert(result.in == wrapped_input.end()); - assert(result.out == move_only_range{actual_output}.end()); - for (int i = 0; i < 3; ++i) { - assert(input1[i].val == -1); - assert(actual_output[i].val == expected_output[i]); - } - } -} - -int main() { - STATIC_ASSERT((smoke_test(), true)); - smoke_test(); -} - -struct instantiator { - template - static void call(In&& in = {}, Out out = {}) { - (void) ranges::move(in, std::move(out)); - (void) ranges::move(ranges::begin(in), ranges::end(in), std::move(out)); - } -}; - -template void test_in_out(); From dd51ae02414ef668d52b52ea7dada6c36dc0f711 Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Tue, 16 Jun 2020 14:38:39 -0400 Subject: [PATCH 18/37] minor changes --- stl/inc/algorithm | 4 +- .../std/tests/P0896R4_ranges_alg_fill/env.lst | 4 -- .../tests/P0896R4_ranges_alg_fill/test.cpp | 57 ------------------- .../P0896R4_ranges_alg_generate/test.cpp | 10 ++-- 4 files changed, 7 insertions(+), 68 deletions(-) delete mode 100644 tests/std/tests/P0896R4_ranges_alg_fill/env.lst delete mode 100644 tests/std/tests/P0896R4_ranges_alg_fill/test.cpp diff --git a/stl/inc/algorithm b/stl/inc/algorithm index 2cbd1902647..6c28d4310f2 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -2389,7 +2389,7 @@ namespace ranges { template requires invocable<_F&> && indirectly_writable<_O, invoke_result_t<_F&>> constexpr _O operator()(_O _First, iter_difference_t<_O> _Count, _F _Gen) const { - auto _UFirst = _Get_unwrapped_n(_STD move(_First), _Count); // what if count is larger than num elems + auto _UFirst = _Get_unwrapped_n(_STD move(_First), _Count); for (; _Count > 0; ++_UFirst, --_Count) { *_UFirst = _Gen(); } @@ -2397,7 +2397,7 @@ namespace ranges { _Seek_wrapped(_First, _STD move(_UFirst)); return _First; } - } + }; inline constexpr _Generate_n_fn generate_n{_Not_quite_object::_Construct_tag{}}; } // namespace ranges diff --git a/tests/std/tests/P0896R4_ranges_alg_fill/env.lst b/tests/std/tests/P0896R4_ranges_alg_fill/env.lst deleted file mode 100644 index f3ccc8613c6..00000000000 --- a/tests/std/tests/P0896R4_ranges_alg_fill/env.lst +++ /dev/null @@ -1,4 +0,0 @@ -# Copyright (c) Microsoft Corporation. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -RUNALL_INCLUDE ..\concepts_matrix.lst diff --git a/tests/std/tests/P0896R4_ranges_alg_fill/test.cpp b/tests/std/tests/P0896R4_ranges_alg_fill/test.cpp deleted file mode 100644 index 7104e6987e4..00000000000 --- a/tests/std/tests/P0896R4_ranges_alg_fill/test.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -#include -#include -#include -#include -#include -#include - -constexpr void smoke_test() { - using ranges::fill, ranges::iterator_t; - using std::same_as; - - int output1[] = {13, 42, 1367}; - int output2[] = {13, 42, 1367}; - { - const int value = 7; - auto result = fill(std::begin(output1), std::end(output1), value); - for (int i = 0; i < 3; ++i) { - assert(output1[i] == 7); - } - assert(result == std::end(output1)); - } - { - const int value = 13; - auto result = fill(output2, value); - for (int i = 0; i < 3; ++i) { - assert(output2[i] == 13); - } - assert(result == std::end(output2)); - int output[] = {13, 42, 1367}; - { - const int value = 7; - auto result = fill(output.begin(), output.end(), value); - for (int i = 0; i < 3; ++i) { - assert(output[i] == 7); - } - assert(result == output.end()); - } -} - -int main() { - STATIC_ASSERT((smoke_test(), true)); - // STATIC_ASSERT((smoke_test(), true)); - smoke_test(); -} - -struct instantiator { - template - static void call(Out&& out = {}) { - (void) ranges::fill(out, 42); - (void) ranges::fill(ranges::begin(out), ranges::end(out), 42); - } -}; - -template void test_in_out(); diff --git a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp index 8887c5ea90d..6dfb191214f 100644 --- a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp @@ -15,14 +15,14 @@ constexpr void smoke_test() { int output1[] = {13, 42, 1367}; int output2[] = {13, 42, 1367}; { - auto result = generate(std::begin(output1), std::end(output1), [](){return 7;}); + auto result = generate(std::begin(output1), std::end(output1), []() { return 7; }); for (int i = 0; i < 3; ++i) { assert(output1[i] == 7); } assert(result == std::end(output1)); } { - auto result = generate(output2, [](){return 13;}); + auto result = generate(output2, []() { return 13; }); for (int i = 0; i < 3; ++i) { assert(output2[i] == 13); } @@ -38,9 +38,9 @@ int main() { struct instantiator { template static void call(Out&& out = {}) { - (void) ranges::generate(out, [](){return 13;}); - (void) ranges::generate(ranges::begin(out), ranges::end(out), [](){return 13;}); + (void) ranges::generate(out, []() { return 13; }); + (void) ranges::generate(ranges::begin(out), ranges::end(out), []() { return 13; }); } }; -template void test_out(); \ No newline at end of file +template void test_out(); From e2c8965bc1f82d43c4c39259dfdbde9925d50dc4 Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Tue, 16 Jun 2020 16:42:03 -0400 Subject: [PATCH 19/37] generate_n tests added --- .../P0869R4_ranges_alg_generate_n/env.lst | 4 +++ .../P0869R4_ranges_alg_generate_n/test.cpp | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 tests/std/tests/P0869R4_ranges_alg_generate_n/env.lst create mode 100644 tests/std/tests/P0869R4_ranges_alg_generate_n/test.cpp diff --git a/tests/std/tests/P0869R4_ranges_alg_generate_n/env.lst b/tests/std/tests/P0869R4_ranges_alg_generate_n/env.lst new file mode 100644 index 00000000000..f3ccc8613c6 --- /dev/null +++ b/tests/std/tests/P0869R4_ranges_alg_generate_n/env.lst @@ -0,0 +1,4 @@ +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +RUNALL_INCLUDE ..\concepts_matrix.lst diff --git a/tests/std/tests/P0869R4_ranges_alg_generate_n/test.cpp b/tests/std/tests/P0869R4_ranges_alg_generate_n/test.cpp new file mode 100644 index 00000000000..c58aaf1ef8e --- /dev/null +++ b/tests/std/tests/P0869R4_ranges_alg_generate_n/test.cpp @@ -0,0 +1,34 @@ +#include +#include +#include +#include +#include +#include + +constexpr void smoke_test() { + using ranges::generate_n, ranges::iterator_t; + using std::same_as; + + int output1[] = {13, 42, 1367}; + { + auto result = generate_n(std::begin(output1), ranges::distance(output1), []() { return 7; }); + for (int i = 0; i < 3; ++i) { + assert(output1[i] == 7); + } + assert(result == std::end(output1)); + } +} + +int main() { + STATIC_ASSERT((smoke_test(), true)); + smoke_test(); +} + +struct instantiator { + template + static void call(Out&& out = {}) { + (void) ranges::generate_n(out, 13, []() { return 13; }); + } +}; + +template void test_out(); From cc7220ad13ef0394e6f20de23a38cd5944a4c03e Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Tue, 16 Jun 2020 16:55:22 -0400 Subject: [PATCH 20/37] similar changes as casey made in fill_n --- stl/inc/algorithm | 2 +- tests/std/tests/P0869R4_ranges_alg_generate_n/test.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stl/inc/algorithm b/stl/inc/algorithm index 6c28d4310f2..e8a0ca533d4 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -2390,7 +2390,7 @@ namespace ranges { requires invocable<_F&> && indirectly_writable<_O, invoke_result_t<_F&>> constexpr _O operator()(_O _First, iter_difference_t<_O> _Count, _F _Gen) const { auto _UFirst = _Get_unwrapped_n(_STD move(_First), _Count); - for (; _Count > 0; ++_UFirst, --_Count) { + for (; _Count > 0; ++_UFirst, (void) --_Count) { *_UFirst = _Gen(); } diff --git a/tests/std/tests/P0869R4_ranges_alg_generate_n/test.cpp b/tests/std/tests/P0869R4_ranges_alg_generate_n/test.cpp index c58aaf1ef8e..083c5580ef2 100644 --- a/tests/std/tests/P0869R4_ranges_alg_generate_n/test.cpp +++ b/tests/std/tests/P0869R4_ranges_alg_generate_n/test.cpp @@ -27,7 +27,7 @@ int main() { struct instantiator { template static void call(Out&& out = {}) { - (void) ranges::generate_n(out, 13, []() { return 13; }); + (void) ranges::generate_n(ranges::begin(out), 13, []() { return 13; }); } }; From e61aa5f6358b02d48360a0d29509231406b2e8f6 Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Wed, 17 Jun 2020 10:41:23 -0400 Subject: [PATCH 21/37] generate and generate_n tests passing now --- stl/inc/algorithm | 4 ++-- .../env.lst | 0 .../test.cpp | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename tests/std/tests/{P0869R4_ranges_alg_generate_n => P0896R4_ranges_alg_generate_n}/env.lst (100%) rename tests/std/tests/{P0869R4_ranges_alg_generate_n => P0896R4_ranges_alg_generate_n}/test.cpp (100%) diff --git a/stl/inc/algorithm b/stl/inc/algorithm index e8a0ca533d4..2a5e070ff58 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -2360,8 +2360,8 @@ namespace ranges { requires invocable<_F&> && indirectly_writable<_O, invoke_result_t<_F&>> constexpr _O operator()(_O _First, _S _Last, _F _Gen) const { _Adl_verify_range(_First, _Last); - auto _UFirst = _Get_unwrapped(_First); - const auto _ULast = _Get_unwrapped(_Last); + auto _UFirst = _Get_unwrapped(_STD move(_First)); + const auto _ULast = _Get_unwrapped(_STD move(_Last)); for (; _UFirst != _ULast; ++_UFirst) { *_UFirst = _Gen(); } diff --git a/tests/std/tests/P0869R4_ranges_alg_generate_n/env.lst b/tests/std/tests/P0896R4_ranges_alg_generate_n/env.lst similarity index 100% rename from tests/std/tests/P0869R4_ranges_alg_generate_n/env.lst rename to tests/std/tests/P0896R4_ranges_alg_generate_n/env.lst diff --git a/tests/std/tests/P0869R4_ranges_alg_generate_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp similarity index 100% rename from tests/std/tests/P0869R4_ranges_alg_generate_n/test.cpp rename to tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp From 9c8acb35b8892275b1dcdcc93fcbfe3df5fdcab6 Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Wed, 17 Jun 2020 12:04:29 -0400 Subject: [PATCH 22/37] minor change --- tests/std/tests/P0896R4_ranges_alg_generate/test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp index 6dfb191214f..c3470dadba7 100644 --- a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp @@ -38,8 +38,8 @@ int main() { struct instantiator { template static void call(Out&& out = {}) { - (void) ranges::generate(out, []() { return 13; }); - (void) ranges::generate(ranges::begin(out), ranges::end(out), []() { return 13; }); + (void) ranges::generate(out, []() { return 42; }); + (void) ranges::generate(ranges::begin(out), ranges::end(out), []() { return 42; }); } }; From 63a57a4529a9632779f60b7b2f0c1ae9188b6cb6 Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Mon, 22 Jun 2020 10:41:07 -0400 Subject: [PATCH 23/37] improved style --- stl/inc/algorithm | 18 +++++++++--------- .../tests/P0896R4_ranges_alg_generate/test.cpp | 14 ++++++++------ .../P0896R4_ranges_alg_generate_n/test.cpp | 13 ++++++------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/stl/inc/algorithm b/stl/inc/algorithm index 2a5e070ff58..03b5a4b1d65 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -2356,9 +2356,9 @@ namespace ranges { using _Not_quite_object::_Not_quite_object; // clang-format off - template _S, copy_constructible _F> - requires invocable<_F&> && indirectly_writable<_O, invoke_result_t<_F&>> - constexpr _O operator()(_O _First, _S _Last, _F _Gen) const { + template _Se, copy_constructible _Fn> + requires invocable<_Fn&> && indirectly_writable<_Out, invoke_result_t<_Fn&>> + constexpr _Out operator()(_Out _First, _Se _Last, _Fn _Gen) const { _Adl_verify_range(_First, _Last); auto _UFirst = _Get_unwrapped(_STD move(_First)); const auto _ULast = _Get_unwrapped(_STD move(_Last)); @@ -2370,9 +2370,9 @@ namespace ranges { return _First; } - template - requires invocable<_F&> && output_range<_R, invoke_result_t<_F&>> - constexpr borrowed_iterator_t<_R> operator()(_R&& _Range, _F _Gen) const { + template + requires invocable<_Fn&> && output_range<_Rng, invoke_result_t<_Fn&>> + constexpr borrowed_iterator_t<_Rng> operator()(_Rng&& _Range, _Fn _Gen) const { return (*this)(_RANGES begin(_Range), _RANGES end(_Range), _Gen); } // clang-format on @@ -2386,9 +2386,9 @@ namespace ranges { using _Not_quite_object::_Not_quite_object; // clang-format off - template - requires invocable<_F&> && indirectly_writable<_O, invoke_result_t<_F&>> - constexpr _O operator()(_O _First, iter_difference_t<_O> _Count, _F _Gen) const { + template + requires invocable<_Fn&> && indirectly_writable<_Out, invoke_result_t<_Fn&>> + constexpr _Out operator()(_Out _First, iter_difference_t<_Out> _Count, _Fn _Gen) const { auto _UFirst = _Get_unwrapped_n(_STD move(_First), _Count); for (; _Count > 0; ++_UFirst, (void) --_Count) { *_UFirst = _Gen(); diff --git a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp index c3470dadba7..332db4a1b9a 100644 --- a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp @@ -15,16 +15,18 @@ constexpr void smoke_test() { int output1[] = {13, 42, 1367}; int output2[] = {13, 42, 1367}; { - auto result = generate(std::begin(output1), std::end(output1), []() { return 7; }); - for (int i = 0; i < 3; ++i) { - assert(output1[i] == 7); + const int value = 7; + auto result = generate(std::begin(output1), std::end(output1), []() { return value; }); + for (auto elem : output1) { + assert(elem == value); } assert(result == std::end(output1)); } { - auto result = generate(output2, []() { return 13; }); - for (int i = 0; i < 3; ++i) { - assert(output2[i] == 13); + const int value = 13; + auto result = generate(output2, []() { return value; }); + for (auto elem : output2) { + assert(elem == value); } assert(result == std::end(output2)); } diff --git a/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp index 083c5580ef2..2947634ef22 100644 --- a/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp @@ -9,14 +9,13 @@ constexpr void smoke_test() { using ranges::generate_n, ranges::iterator_t; using std::same_as; - int output1[] = {13, 42, 1367}; - { - auto result = generate_n(std::begin(output1), ranges::distance(output1), []() { return 7; }); - for (int i = 0; i < 3; ++i) { - assert(output1[i] == 7); - } - assert(result == std::end(output1)); + int output[] = {13, 42, 1367}; + const int value = 7; + auto result = generate_n(std::begin(output), ranges::distance(output), []() { return value; }); + for (auto elem : output) { + assert(elem == value); } + assert(result == std::end(output)); } int main() { From b0fb0334991d546a8c101f51d7a66575babc0d26 Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Mon, 22 Jun 2020 10:42:42 -0400 Subject: [PATCH 24/37] added copyright banner --- tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp index 2947634ef22..d2c2f6e49ac 100644 --- a/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + #include #include #include From 1c7b54d0f50892b765f69ad8ab17365f962d9c55 Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Mon, 22 Jun 2020 10:51:47 -0400 Subject: [PATCH 25/37] minor deindented algo --- stl/inc/algorithm | 54 +++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/stl/inc/algorithm b/stl/inc/algorithm index 03b5a4b1d65..23567ac8e4c 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -2356,25 +2356,25 @@ namespace ranges { using _Not_quite_object::_Not_quite_object; // clang-format off - template _Se, copy_constructible _Fn> - requires invocable<_Fn&> && indirectly_writable<_Out, invoke_result_t<_Fn&>> - constexpr _Out operator()(_Out _First, _Se _Last, _Fn _Gen) const { - _Adl_verify_range(_First, _Last); - auto _UFirst = _Get_unwrapped(_STD move(_First)); - const auto _ULast = _Get_unwrapped(_STD move(_Last)); - for (; _UFirst != _ULast; ++_UFirst) { - *_UFirst = _Gen(); - } - - _Seek_wrapped(_First, _STD move(_UFirst)); - return _First; + template _Se, copy_constructible _Fn> + requires invocable<_Fn&> && indirectly_writable<_Out, invoke_result_t<_Fn&>> + constexpr _Out operator()(_Out _First, _Se _Last, _Fn _Gen) const { + _Adl_verify_range(_First, _Last); + auto _UFirst = _Get_unwrapped(_STD move(_First)); + const auto _ULast = _Get_unwrapped(_STD move(_Last)); + for (; _UFirst != _ULast; ++_UFirst) { + *_UFirst = _Gen(); } - template - requires invocable<_Fn&> && output_range<_Rng, invoke_result_t<_Fn&>> - constexpr borrowed_iterator_t<_Rng> operator()(_Rng&& _Range, _Fn _Gen) const { - return (*this)(_RANGES begin(_Range), _RANGES end(_Range), _Gen); - } + _Seek_wrapped(_First, _STD move(_UFirst)); + return _First; + } + + template + requires invocable<_Fn&> && output_range<_Rng, invoke_result_t<_Fn&>> + constexpr borrowed_iterator_t<_Rng> operator()(_Rng&& _Range, _Fn _Gen) const { + return (*this)(_RANGES begin(_Range), _RANGES end(_Range), _Gen); + } // clang-format on }; @@ -2386,17 +2386,17 @@ namespace ranges { using _Not_quite_object::_Not_quite_object; // clang-format off - template - requires invocable<_Fn&> && indirectly_writable<_Out, invoke_result_t<_Fn&>> - constexpr _Out operator()(_Out _First, iter_difference_t<_Out> _Count, _Fn _Gen) const { - auto _UFirst = _Get_unwrapped_n(_STD move(_First), _Count); - for (; _Count > 0; ++_UFirst, (void) --_Count) { - *_UFirst = _Gen(); - } - - _Seek_wrapped(_First, _STD move(_UFirst)); - return _First; + template + requires invocable<_Fn&> && indirectly_writable<_Out, invoke_result_t<_Fn&>> + constexpr _Out operator()(_Out _First, iter_difference_t<_Out> _Count, _Fn _Gen) const { + auto _UFirst = _Get_unwrapped_n(_STD move(_First), _Count); + for (; _Count > 0; ++_UFirst, (void) --_Count) { + *_UFirst = _Gen(); } + + _Seek_wrapped(_First, _STD move(_UFirst)); + return _First; + } }; inline constexpr _Generate_n_fn generate_n{_Not_quite_object::_Construct_tag{}}; From e13beda0c80e5486a2cfeb705b6d65a744d59786 Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Tue, 23 Jun 2020 10:16:27 -0400 Subject: [PATCH 26/37] tried to write a better test for generate but it threw a bunch of errors with static variable in lambda expression --- stl/inc/algorithm | 2 +- .../P0896R4_ranges_alg_generate/test.cpp | 28 +++++++++++++------ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/stl/inc/algorithm b/stl/inc/algorithm index 23567ac8e4c..b621256a6e9 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -5234,4 +5234,4 @@ _STL_RESTORE_CLANG_WARNINGS #pragma warning(pop) #pragma pack(pop) #endif // _STL_COMPILER_PREPROCESSOR -#endif // _ALGORITHM_ +#endif // _ALGORITHM_ \ No newline at end of file diff --git a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp index 332db4a1b9a..db8b05c538c 100644 --- a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp @@ -12,24 +12,36 @@ constexpr void smoke_test() { using ranges::generate, ranges::iterator_t; using std::same_as; - int output1[] = {13, 42, 1367}; - int output2[] = {13, 42, 1367}; { + int output[] = {13, 42, 1367}; const int value = 7; - auto result = generate(std::begin(output1), std::end(output1), []() { return value; }); - for (auto elem : output1) { + auto result = generate(std::begin(output), std::end(output), []() { return value; }); + for (auto elem : output) { assert(elem == value); } - assert(result == std::end(output1)); + assert(result == std::end(output)); } { + int output[] = {13, 42, 1367}; const int value = 13; - auto result = generate(output2, []() { return value; }); - for (auto elem : output2) { + auto result = generate(output, []() { return value; }); + for (auto elem : output) { assert(elem == value); } - assert(result == std::end(output2)); + assert(result == std::end(output)); } + // { + // int output[] = {13, 42, 1367}; + // auto result = generate(output, []() { + // static int calls_to_generate = 0; + // calls_to_generate++; + // return calls_to_generate; + // }); + // // for (auto elem : output) { + // // assert(elem == value); + // // } + // assert(result == std::end(output)); + // } } int main() { From b8a91e3e4533536db8a138f663a664f565e7a5d1 Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Tue, 23 Jun 2020 10:53:30 -0400 Subject: [PATCH 27/37] trimmed white space --- stl/inc/algorithm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stl/inc/algorithm b/stl/inc/algorithm index b621256a6e9..e85ad974a14 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -2389,7 +2389,7 @@ namespace ranges { template requires invocable<_Fn&> && indirectly_writable<_Out, invoke_result_t<_Fn&>> constexpr _Out operator()(_Out _First, iter_difference_t<_Out> _Count, _Fn _Gen) const { - auto _UFirst = _Get_unwrapped_n(_STD move(_First), _Count); + auto _UFirst = _Get_unwrapped_n(_STD move(_First), _Count); for (; _Count > 0; ++_UFirst, (void) --_Count) { *_UFirst = _Gen(); } @@ -5234,4 +5234,4 @@ _STL_RESTORE_CLANG_WARNINGS #pragma warning(pop) #pragma pack(pop) #endif // _STL_COMPILER_PREPROCESSOR -#endif // _ALGORITHM_ \ No newline at end of file +#endif // _ALGORITHM_ From 947f2ddb86aea48620223990d5883e263fd608f4 Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Tue, 23 Jun 2020 16:48:24 -0400 Subject: [PATCH 28/37] made the function being passed into generate be non-constant --- .../P0896R4_ranges_alg_generate/test.cpp | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp index db8b05c538c..886ae547742 100644 --- a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp @@ -30,18 +30,18 @@ constexpr void smoke_test() { } assert(result == std::end(output)); } - // { - // int output[] = {13, 42, 1367}; - // auto result = generate(output, []() { - // static int calls_to_generate = 0; - // calls_to_generate++; - // return calls_to_generate; - // }); - // // for (auto elem : output) { - // // assert(elem == value); - // // } - // assert(result == std::end(output)); - // } + { + int output[] = {13, 42, 1367}; + int calls_to_generate = -1; + auto result = generate(output, [&calls_to_generate]() { + calls_to_generate++; + return calls_to_generate; + }); + for (int i = 0; i < 3; i++) { + assert(i == output[i]); + } + assert(result == std::end(output)); + } } int main() { From c51d3a0127832833a3cc30b3e489aa5f803c6d3b Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Wed, 24 Jun 2020 10:23:01 -0400 Subject: [PATCH 29/37] ++i instead of i++ --- tests/std/tests/P0896R4_ranges_alg_generate/test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp index 886ae547742..14fbccd0930 100644 --- a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp @@ -37,7 +37,7 @@ constexpr void smoke_test() { calls_to_generate++; return calls_to_generate; }); - for (int i = 0; i < 3; i++) { + for (int i = 0; i < 3; ++i) { assert(i == output[i]); } assert(result == std::end(output)); From d9544057ddbaeeccbef9d31aa739d259a5613659 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Wed, 24 Jun 2020 19:07:12 -0700 Subject: [PATCH 30/37] Run clang-format after merging. --- tests/std/tests/P0896R4_ranges_alg_generate/test.cpp | 3 ++- tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp index 14fbccd0930..e8e1947ac6b 100644 --- a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp @@ -4,10 +4,11 @@ #include #include #include -#include #include #include +#include + constexpr void smoke_test() { using ranges::generate, ranges::iterator_t; using std::same_as; diff --git a/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp index d2c2f6e49ac..69c1063b98d 100644 --- a/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp @@ -4,10 +4,11 @@ #include #include #include -#include #include #include +#include + constexpr void smoke_test() { using ranges::generate_n, ranges::iterator_t; using std::same_as; From 3bb5a622c3685c643df340b28502d657eda6ff74 Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Thu, 25 Jun 2020 14:28:46 -0400 Subject: [PATCH 31/37] fixed toda condition and lambda function testing --- llvm-project | 2 +- stl/inc/algorithm | 14 ++++++++------ .../P0896R4_ranges_alg_generate/test.cpp | 19 +++++++++---------- .../P0896R4_ranges_alg_generate_n/test.cpp | 14 ++++++++------ 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/llvm-project b/llvm-project index d66428cb995..634a0acb307 160000 --- a/llvm-project +++ b/llvm-project @@ -1 +1 @@ -Subproject commit d66428cb995c7a04ecb02951d5021d815fc02b2b +Subproject commit 634a0acb307ddad21c5542dc313e02b4df9b216e diff --git a/stl/inc/algorithm b/stl/inc/algorithm index 85edcb47b30..58552fcd71c 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -2866,7 +2866,7 @@ namespace ranges { template requires invocable<_Fn&> && output_range<_Rng, invoke_result_t<_Fn&>> constexpr borrowed_iterator_t<_Rng> operator()(_Rng&& _Range, _Fn _Gen) const { - return (*this)(_RANGES begin(_Range), _RANGES end(_Range), _Gen); + return (*this)(_RANGES begin(_Range), _RANGES end(_Range), _Pass_fn(_Gen)); } // clang-format on }; @@ -2882,12 +2882,14 @@ namespace ranges { template requires invocable<_Fn&> && indirectly_writable<_Out, invoke_result_t<_Fn&>> constexpr _Out operator()(_Out _First, iter_difference_t<_Out> _Count, _Fn _Gen) const { - auto _UFirst = _Get_unwrapped_n(_STD move(_First), _Count); - for (; _Count > 0; ++_UFirst, (void) --_Count) { - *_UFirst = _Gen(); - } + if (0 <= _Count) { + auto _UFirst = _Get_unwrapped_n(_STD move(_First), _Count); + for (; _Count > 0; ++_UFirst, (void) --_Count) { + *_UFirst = _Gen(); + } - _Seek_wrapped(_First, _STD move(_UFirst)); + _Seek_wrapped(_First, _STD move(_UFirst)); + } return _First; } }; diff --git a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp index e8e1947ac6b..527ee6855ac 100644 --- a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp @@ -16,32 +16,31 @@ constexpr void smoke_test() { { int output[] = {13, 42, 1367}; const int value = 7; - auto result = generate(std::begin(output), std::end(output), []() { return value; }); - for (auto elem : output) { + auto result = generate(ranges::begin(output), ranges::end(output), []() { return value; }); + for (const auto& elem : output) { assert(elem == value); } - assert(result == std::end(output)); + assert(result == ranges::end(output)); } { int output[] = {13, 42, 1367}; const int value = 13; auto result = generate(output, []() { return value; }); - for (auto elem : output) { + for (const auto& elem : output) { assert(elem == value); } - assert(result == std::end(output)); + assert(result == ranges::end(output)); } { - int output[] = {13, 42, 1367}; - int calls_to_generate = -1; - auto result = generate(output, [&calls_to_generate]() { - calls_to_generate++; + int output[] = {13, 42, 1367}; + auto result = generate(output, [calls_to_generate = -1]() mutable { + ++calls_to_generate; return calls_to_generate; }); for (int i = 0; i < 3; ++i) { assert(i == output[i]); } - assert(result == std::end(output)); + assert(result == ranges::end(output)); } } diff --git a/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp index 69c1063b98d..83574318869 100644 --- a/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp @@ -13,13 +13,15 @@ constexpr void smoke_test() { using ranges::generate_n, ranges::iterator_t; using std::same_as; - int output[] = {13, 42, 1367}; - const int value = 7; - auto result = generate_n(std::begin(output), ranges::distance(output), []() { return value; }); - for (auto elem : output) { - assert(elem == value); + int output[] = {13, 42, 1367}; + auto result = generate_n(ranges::begin(output), ranges::distance(output), [calls_to_generate = -1]() mutable { + ++calls_to_generate; + return calls_to_generate; + }); + for (int i = 0; i < 3; ++i) { + assert(i == output[i]); } - assert(result == std::end(output)); + assert(result == ranges::end(output)); } int main() { From 37b38d9d2999033ded99cee41bdccfe5f0ac8f40 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Wed, 1 Jul 2020 18:49:34 -0700 Subject: [PATCH 32/37] tiny fixes: * revert inadvertent change to LLVM reference * update `range_algorithm_support.hpp` from `fill` PR to reduce future merge conflicts --- llvm-project | 2 +- tests/std/include/range_algorithm_support.hpp | 182 +++++------------- 2 files changed, 49 insertions(+), 135 deletions(-) diff --git a/llvm-project b/llvm-project index 634a0acb307..d66428cb995 160000 --- a/llvm-project +++ b/llvm-project @@ -1 +1 @@ -Subproject commit 634a0acb307ddad21c5542dc313e02b4df9b216e +Subproject commit d66428cb995c7a04ecb02951d5021d815fc02b2b diff --git a/tests/std/include/range_algorithm_support.hpp b/tests/std/include/range_algorithm_support.hpp index f724113ce81..c02c977f56a 100644 --- a/tests/std/include/range_algorithm_support.hpp +++ b/tests/std/include/range_algorithm_support.hpp @@ -723,50 +723,11 @@ struct with_bidirectional_ranges { }; template -struct with_output_ranges { +struct with_forward_ranges { template - static void call() { + static constexpr void call() { using namespace test; - // For all ranges, IsCommon implies Eq. - // For single-pass ranges, Eq is uninteresting without IsCommon (there's only one valid iterator - // value at a time, and no reason to compare it with itself for equality). - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - // forward always has Eq; !IsSized && Diff is uninteresting (sized_range is sized_range). Continuation::template call>(); @@ -793,108 +754,61 @@ struct with_output_ranges { Continuation::template call>(); - // Ditto always Eq; !IsSized && Diff is uninteresting (ranges::size still works). - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - - // Ditto always Eq; !IsSized && SizedSentinel is uninteresting (ranges::size works either way), as is - // !IsSized && IsCommon. - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - - // Ditto always Eq; !IsSized && SizedSentinel is uninteresting (ranges::size still works), as is - // !IsSized && IsCommon. contiguous also implies !Proxy. - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); - Continuation::template call>(); + with_bidirectional_ranges::template call(); } }; template -struct with_forward_ranges { +struct with_input_ranges { template static constexpr void call() { using namespace test; - // forward always has Eq; !IsSized && Diff is uninteresting (sized_range is sized_range). + // For all ranges, IsCommon implies Eq. + // For single-pass ranges, Eq is uninteresting without IsCommon (there's only one valid iterator + // value at a time, and no reason to compare it with itself for equality). Continuation::template call>(); + range>(); Continuation::template call>(); + range>(); Continuation::template call>(); + range>(); Continuation::template call>(); + range>(); + Continuation::template call>(); + range>(); Continuation::template call>(); + range>(); Continuation::template call>(); + range>(); Continuation::template call>(); + range>(); + Continuation::template call>(); + range>(); Continuation::template call>(); + range>(); Continuation::template call>(); + range>(); Continuation::template call>(); + range>(); - with_bidirectional_ranges::template call(); + Continuation::template call>(); + Continuation::template call>(); + Continuation::template call>(); + Continuation::template call>(); + + with_forward_ranges::template call(); } }; template -struct with_input_ranges { +struct with_output_ranges { template static constexpr void call() { using namespace test; @@ -903,40 +817,40 @@ struct with_input_ranges { // For single-pass ranges, Eq is uninteresting without IsCommon (there's only one valid iterator // value at a time, and no reason to compare it with itself for equality). Continuation::template call>(); + range>(); Continuation::template call>(); + range>(); Continuation::template call>(); + range>(); Continuation::template call>(); + range>(); Continuation::template call>(); + range>(); Continuation::template call>(); + range>(); Continuation::template call>(); + range>(); Continuation::template call>(); + range>(); Continuation::template call>(); + range>(); Continuation::template call>(); + range>(); Continuation::template call>(); + range>(); Continuation::template call>(); + range>(); Continuation::template call>(); + range>(); Continuation::template call>(); + range>(); Continuation::template call>(); + range>(); Continuation::template call>(); + range>(); with_forward_ranges::template call(); } From a985e795e156bd07ddc3e7ab79bec9bffb025549 Mon Sep 17 00:00:00 2001 From: Ahana Mukhopadhyay Date: Mon, 6 Jul 2020 11:07:07 -0400 Subject: [PATCH 33/37] added test for 0 and -1 for generate_n --- stl/inc/algorithm | 2 +- .../P0896R4_ranges_alg_generate/test.cpp | 3 +- .../P0896R4_ranges_alg_generate_n/test.cpp | 42 ++++++++++++++----- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/stl/inc/algorithm b/stl/inc/algorithm index 9edac56f6f2..d1a9a22d164 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -3044,7 +3044,7 @@ namespace ranges { template requires invocable<_Fn&> && indirectly_writable<_Out, invoke_result_t<_Fn&>> constexpr _Out operator()(_Out _First, iter_difference_t<_Out> _Count, _Fn _Gen) const { - if (0 <= _Count) { + if (_Count > 0) { auto _UFirst = _Get_unwrapped_n(_STD move(_First), _Count); for (; _Count > 0; ++_UFirst, (void) --_Count) { *_UFirst = _Gen(); diff --git a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp index 527ee6855ac..32e1a28a6ca 100644 --- a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp @@ -10,8 +10,7 @@ #include constexpr void smoke_test() { - using ranges::generate, ranges::iterator_t; - using std::same_as; + using ranges::generate; { int output[] = {13, 42, 1367}; diff --git a/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp index 83574318869..73d265dc0ad 100644 --- a/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp @@ -10,18 +10,38 @@ #include constexpr void smoke_test() { - using ranges::generate_n, ranges::iterator_t; - using std::same_as; - - int output[] = {13, 42, 1367}; - auto result = generate_n(ranges::begin(output), ranges::distance(output), [calls_to_generate = -1]() mutable { - ++calls_to_generate; - return calls_to_generate; - }); - for (int i = 0; i < 3; ++i) { - assert(i == output[i]); + using ranges::generate_n, ranges::equal; + { + int output[] = {13, 42, 1367}; + auto result = generate_n(ranges::begin(output), ranges::distance(output), [calls_to_generate = -1]() mutable { + ++calls_to_generate; + return calls_to_generate; + }); + for (int i = 0; i < 3; ++i) { + assert(i == output[i]); + } + assert(result == ranges::end(output)); + } + { + int expected_output[] = {13, 42, 1367}; + int output[] = {13, 42, 1367}; + auto result = generate_n(ranges::begin(output), 0, [calls_to_generate = -1]() mutable { + ++calls_to_generate; + return calls_to_generate; + }); + assert(ranges::equal(output, expected_output)); + assert(result == ranges::begin(output)); + } + { + int expected_output[] = {13, 42, 1367}; + int output[] = {13, 42, 1367}; + auto result = generate_n(ranges::begin(output), -1, [calls_to_generate = -1]() mutable { + ++calls_to_generate; + return calls_to_generate; + }); + assert(ranges::equal(output, expected_output)); + assert(result == ranges::begin(output)); } - assert(result == ranges::end(output)); } int main() { From b2d281afeeb0b7e7dcab8480d9977c0819f6cec1 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Wed, 8 Jul 2020 09:30:40 -0700 Subject: [PATCH 34/37] Review comments; modernize --- stl/inc/algorithm | 36 +++++--- tests/std/include/range_algorithm_support.hpp | 8 +- .../P0896R4_ranges_alg_generate/test.cpp | 67 ++++++--------- .../P0896R4_ranges_alg_generate_n/test.cpp | 82 +++++++++---------- 4 files changed, 93 insertions(+), 100 deletions(-) diff --git a/stl/inc/algorithm b/stl/inc/algorithm index 8d4d6d15bd2..cdfb5f85a9d 100644 --- a/stl/inc/algorithm +++ b/stl/inc/algorithm @@ -3163,6 +3163,7 @@ namespace ranges { _Seek_wrapped(_First, _STD move(_UFirst)); } + return _First; } }; @@ -3179,22 +3180,35 @@ namespace ranges { requires invocable<_Fn&> && indirectly_writable<_Out, invoke_result_t<_Fn&>> constexpr _Out operator()(_Out _First, _Se _Last, _Fn _Gen) const { _Adl_verify_range(_First, _Last); - auto _UFirst = _Get_unwrapped(_STD move(_First)); - const auto _ULast = _Get_unwrapped(_STD move(_Last)); - for (; _UFirst != _ULast; ++_UFirst) { - *_UFirst = _Gen(); - } - - _Seek_wrapped(_First, _STD move(_UFirst)); + _Seek_wrapped(_First, _Generate_unchecked(_Get_unwrapped(_STD move(_First)), + _Get_unwrapped(_STD move(_Last)), _Pass_fn(_Gen))); return _First; } template requires invocable<_Fn&> && output_range<_Rng, invoke_result_t<_Fn&>> constexpr borrowed_iterator_t<_Rng> operator()(_Rng&& _Range, _Fn _Gen) const { - return (*this)(_RANGES begin(_Range), _RANGES end(_Range), _Pass_fn(_Gen)); + auto _First = _RANGES begin(_Range); + _Seek_wrapped( + _First, _Generate_unchecked(_Get_unwrapped(_STD move(_First)), _Uend(_Range), _Pass_fn(_Gen))); + return _First; } // clang-format on + private: + template + _NODISCARD static constexpr _Out _Generate_unchecked(_Out _First, const _Se _Last, _Fn _Gen) { + _STL_INTERNAL_STATIC_ASSERT(input_or_output_iterator<_Out>); + _STL_INTERNAL_STATIC_ASSERT(sentinel_for<_Se, _Out>); + _STL_INTERNAL_STATIC_ASSERT(copy_constructible<_Fn>); + _STL_INTERNAL_STATIC_ASSERT(invocable<_Fn&>); + _STL_INTERNAL_STATIC_ASSERT(indirectly_writable<_Out, invoke_result_t<_Fn&>>); + + for (; _First != _Last; ++_First) { + *_First = _Gen(); + } + + return _First; + } }; inline constexpr _Generate_fn generate{_Not_quite_object::_Construct_tag{}}; @@ -3210,12 +3224,14 @@ namespace ranges { constexpr _Out operator()(_Out _First, iter_difference_t<_Out> _Count, _Fn _Gen) const { if (_Count > 0) { auto _UFirst = _Get_unwrapped_n(_STD move(_First), _Count); - for (; _Count > 0; ++_UFirst, (void) --_Count) { + do { *_UFirst = _Gen(); - } + ++_UFirst; + } while (--_Count > 0); _Seek_wrapped(_First, _STD move(_UFirst)); } + return _First; } }; diff --git a/tests/std/include/range_algorithm_support.hpp b/tests/std/include/range_algorithm_support.hpp index 6188ed7c2ec..b02043749a9 100644 --- a/tests/std/include/range_algorithm_support.hpp +++ b/tests/std/include/range_algorithm_support.hpp @@ -807,7 +807,7 @@ struct with_input_ranges { } }; -template +template struct with_output_ranges { template static constexpr void call() { @@ -856,7 +856,7 @@ struct with_output_ranges { } }; -template +template struct with_input_iterators { template static constexpr void call() { @@ -895,12 +895,12 @@ struct with_input_iterators { } }; -template +template constexpr void test_out() { with_output_ranges::call(); } -template +template constexpr void test_in() { with_input_ranges::call(); } diff --git a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp index 32e1a28a6ca..9ec7bfcaa25 100644 --- a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp @@ -5,55 +5,38 @@ #include #include #include -#include #include -constexpr void smoke_test() { - using ranges::generate; +struct instantiator { + template Out> + static constexpr void call() { + using ranges::generate; - { - int output[] = {13, 42, 1367}; - const int value = 7; - auto result = generate(ranges::begin(output), ranges::end(output), []() { return value; }); - for (const auto& elem : output) { - assert(elem == value); - } - assert(result == ranges::end(output)); - } - { - int output[] = {13, 42, 1367}; - const int value = 13; - auto result = generate(output, []() { return value; }); - for (const auto& elem : output) { - assert(elem == value); + const auto iota_gen = [count = 0]() mutable { return count++; }; + + { + int output[] = {13, 42, 1367}; + Out out_wrapper{output}; + auto result = generate(out_wrapper, iota_gen); + assert(result == out_wrapper.end()); + for (int i = 0; i < 3; ++i) { + assert(i == output[i]); + } } - assert(result == ranges::end(output)); - } - { - int output[] = {13, 42, 1367}; - auto result = generate(output, [calls_to_generate = -1]() mutable { - ++calls_to_generate; - return calls_to_generate; - }); - for (int i = 0; i < 3; ++i) { - assert(i == output[i]); + { + int output[] = {13, 42, 1367}; + Out out_wrapper{output}; + auto result = generate(out_wrapper.begin(), out_wrapper.end(), iota_gen); + assert(result == out_wrapper.end()); + for (int i = 0; i < 3; ++i) { + assert(i == output[i]); + } } - assert(result == ranges::end(output)); } -} +}; int main() { - STATIC_ASSERT((smoke_test(), true)); - smoke_test(); + STATIC_ASSERT((test_out(), true)); + test_out(); } - -struct instantiator { - template - static void call(Out&& out = {}) { - (void) ranges::generate(out, []() { return 42; }); - (void) ranges::generate(ranges::begin(out), ranges::end(out), []() { return 42; }); - } -}; - -template void test_out(); diff --git a/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp index 73d265dc0ad..27aa5b01bd5 100644 --- a/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp @@ -5,55 +5,49 @@ #include #include #include -#include #include -constexpr void smoke_test() { - using ranges::generate_n, ranges::equal; - { - int output[] = {13, 42, 1367}; - auto result = generate_n(ranges::begin(output), ranges::distance(output), [calls_to_generate = -1]() mutable { - ++calls_to_generate; - return calls_to_generate; - }); - for (int i = 0; i < 3; ++i) { - assert(i == output[i]); - } - assert(result == ranges::end(output)); - } - { - int expected_output[] = {13, 42, 1367}; - int output[] = {13, 42, 1367}; - auto result = generate_n(ranges::begin(output), 0, [calls_to_generate = -1]() mutable { - ++calls_to_generate; - return calls_to_generate; - }); - assert(ranges::equal(output, expected_output)); - assert(result == ranges::begin(output)); - } - { - int expected_output[] = {13, 42, 1367}; - int output[] = {13, 42, 1367}; - auto result = generate_n(ranges::begin(output), -1, [calls_to_generate = -1]() mutable { - ++calls_to_generate; - return calls_to_generate; - }); - assert(ranges::equal(output, expected_output)); - assert(result == ranges::begin(output)); - } -} - -int main() { - STATIC_ASSERT((smoke_test(), true)); - smoke_test(); -} +using namespace std; struct instantiator { - template - static void call(Out&& out = {}) { - (void) ranges::generate_n(ranges::begin(out), 13, []() { return 13; }); + template Out> + static constexpr void call() { + using ranges::generate_n, ranges::equal, ranges::iterator_t; + + const auto iota_gen = [count = 0]() mutable { return count++; }; + + { + int output[] = {13, 42, 1367}; + Out out_wrapper{output}; + auto result = generate_n(out_wrapper.begin(), ranges::distance(output), iota_gen); + STATIC_ASSERT(same_as>); + assert(result == out_wrapper.end()); + for (int i = 0; i < 3; ++i) { + assert(i == output[i]); + } + } + + constexpr int expected_output[] = {13, 42, 1367}; + int output[] = {13, 42, 1367}; + { + Out out_wrapper{output}; + auto result = generate_n(out_wrapper.begin(), 0, iota_gen); + STATIC_ASSERT(same_as>); + assert(result.peek() == output); + assert(equal(output, expected_output)); + } + { + Out out_wrapper{output}; + auto result = generate_n(out_wrapper.begin(), -1, iota_gen); + STATIC_ASSERT(same_as>); + assert(result.peek() == output); + assert(equal(output, expected_output)); + } } }; -template void test_out(); +int main() { + STATIC_ASSERT((test_out(), true)); + test_out(); +} From 053cda7eef305be111214e1a4ebf09ef650614bd Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Wed, 8 Jul 2020 16:56:36 -0700 Subject: [PATCH 35/37] Review comments --- tests/std/tests/P0896R4_ranges_alg_generate/test.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp index 9ec7bfcaa25..59e52ab4b05 100644 --- a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp @@ -8,10 +8,12 @@ #include +using namespace std; + struct instantiator { template Out> static constexpr void call() { - using ranges::generate; + using ranges::generate, ranges::iterator_t; const auto iota_gen = [count = 0]() mutable { return count++; }; @@ -19,6 +21,7 @@ struct instantiator { int output[] = {13, 42, 1367}; Out out_wrapper{output}; auto result = generate(out_wrapper, iota_gen); + STATIC_ASSERT(same_as>); assert(result == out_wrapper.end()); for (int i = 0; i < 3; ++i) { assert(i == output[i]); @@ -28,6 +31,7 @@ struct instantiator { int output[] = {13, 42, 1367}; Out out_wrapper{output}; auto result = generate(out_wrapper.begin(), out_wrapper.end(), iota_gen); + STATIC_ASSERT(same_as>); assert(result == out_wrapper.end()); for (int i = 0; i < 3; ++i) { assert(i == output[i]); From 40ddeac634f4eff6bc734b5b7c91a48347b2acdb Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Wed, 8 Jul 2020 17:16:09 -0700 Subject: [PATCH 36/37] Apply suggestions from code review Co-authored-by: Stephan T. Lavavej --- tests/std/tests/P0896R4_ranges_alg_generate/test.cpp | 2 +- tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp index 59e52ab4b05..b3d3eb89727 100644 --- a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp @@ -15,7 +15,7 @@ struct instantiator { static constexpr void call() { using ranges::generate, ranges::iterator_t; - const auto iota_gen = [count = 0]() mutable { return count++; }; + const auto iota_gen = [val = 0]() mutable { return val++; }; { int output[] = {13, 42, 1367}; diff --git a/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp b/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp index 27aa5b01bd5..f08ba74d46d 100644 --- a/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_generate_n/test.cpp @@ -15,7 +15,7 @@ struct instantiator { static constexpr void call() { using ranges::generate_n, ranges::equal, ranges::iterator_t; - const auto iota_gen = [count = 0]() mutable { return count++; }; + const auto iota_gen = [val = 0]() mutable { return val++; }; { int output[] = {13, 42, 1367}; From 81b8b7018ae53f6d9c50f5935c3b1e0912d866b0 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Fri, 10 Jul 2020 12:07:47 -0700 Subject: [PATCH 37/37] Miya's 11th hour save --- tests/std/tests/P0896R4_ranges_alg_generate/test.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp index b3d3eb89727..6d9cb19528a 100644 --- a/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp +++ b/tests/std/tests/P0896R4_ranges_alg_generate/test.cpp @@ -10,13 +10,17 @@ using namespace std; +constexpr auto iota_gen = [val = 0]() mutable { return val++; }; + +// Validate dangling story +STATIC_ASSERT(same_as{}, iota_gen)), ranges::dangling>); +STATIC_ASSERT(same_as{}, iota_gen)), int*>); + struct instantiator { template Out> static constexpr void call() { using ranges::generate, ranges::iterator_t; - const auto iota_gen = [val = 0]() mutable { return val++; }; - { int output[] = {13, 42, 1367}; Out out_wrapper{output};