-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Implement ranges::rotate and ranges::rotate_copy #1073
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
11da98f
Implement ranges::rotate
miscco fdd5c00
Apply Caseys review comments
miscco f54e076
Move ranges::rotate in front of rotate_copy
miscco ba4baa0
Merge branch 'master' into ranges_rotate
miscco 44d9cfa
Fix stupidness
miscco 1aedf8f
Polish:
CaseyCarter cd0865d
Fix typo
CaseyCarter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| RUNALL_INCLUDE ..\concepts_matrix.lst |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #include <algorithm> | ||
| #include <cassert> | ||
| #include <concepts> | ||
| #include <ranges> | ||
| #include <utility> | ||
|
|
||
| #include <range_algorithm_support.hpp> | ||
| using namespace std; | ||
| using P = pair<int, int>; | ||
|
|
||
| // Validate dangling story | ||
| STATIC_ASSERT(same_as<decltype(ranges::rotate(borrowed<false>{}, nullptr_to<int>)), ranges::dangling>); | ||
| STATIC_ASSERT(same_as<decltype(ranges::rotate(borrowed<true>{}, nullptr_to<int>)), ranges::subrange<int*>>); | ||
|
|
||
| struct instantiator { | ||
| static constexpr P expected[5] = {{3, 47}, {4, 99}, {0, 99}, {1, 47}, {2, 99}}; | ||
|
|
||
| template <ranges::forward_range ReadWrite> | ||
| static constexpr void call() { | ||
| using ranges::rotate, ranges::subrange, ranges::equal, ranges::iterator_t; | ||
| { // Validate iterator overload | ||
| P input[5] = {{0, 99}, {1, 47}, {2, 99}, {3, 47}, {4, 99}}; | ||
| ReadWrite wrapped_input{input}; | ||
|
|
||
| auto result = rotate(wrapped_input.begin(), next(wrapped_input.begin(), 3), wrapped_input.end()); | ||
| STATIC_ASSERT(same_as<decltype(result), subrange<iterator_t<ReadWrite>>>); | ||
| assert(result.begin() == next(wrapped_input.begin(), 2)); | ||
| assert(result.end() == wrapped_input.end()); | ||
| assert(equal(expected, input)); | ||
| } | ||
| { // Validate range overload | ||
| P input[5] = {{0, 99}, {1, 47}, {2, 99}, {3, 47}, {4, 99}}; | ||
| ReadWrite wrapped_input{input}; | ||
|
|
||
| auto result = rotate(wrapped_input, next(wrapped_input.begin(), 3)); | ||
| STATIC_ASSERT(same_as<decltype(result), subrange<iterator_t<ReadWrite>>>); | ||
| assert(result.begin() == next(wrapped_input.begin(), 2)); | ||
| assert(result.end() == wrapped_input.end()); | ||
| assert(equal(expected, input)); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| int main() { | ||
| #if defined(__clang__) || defined(__EDG__) // TRANSITION, VSO-938163 | ||
| STATIC_ASSERT((test_fwd<instantiator, P>(), true)); | ||
| #endif // TRANSITION, VSO-938163 | ||
| test_fwd<instantiator, P>(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| RUNALL_INCLUDE ..\concepts_matrix.lst |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #include <algorithm> | ||
| #include <cassert> | ||
| #include <concepts> | ||
| #include <ranges> | ||
|
|
||
| #include <range_algorithm_support.hpp> | ||
| using namespace std; | ||
|
|
||
| // Validate that rotate_copy_result aliases in_out_result | ||
| STATIC_ASSERT(same_as<ranges::rotate_copy_result<int, double>, ranges::in_out_result<int, double>>); | ||
|
|
||
| // Validate dangling story | ||
| STATIC_ASSERT(same_as<decltype(ranges::rotate_copy(borrowed<false>{}, nullptr_to<int>, nullptr_to<int>)), | ||
| ranges::rotate_copy_result<ranges::dangling, int*>>); | ||
| STATIC_ASSERT(same_as<decltype(ranges::rotate_copy(borrowed<true>{}, nullptr_to<int>, nullptr_to<int>)), | ||
| ranges::rotate_copy_result<int*, int*>>); | ||
|
|
||
| struct instantiator { | ||
| static constexpr int input[5] = {1, 2, 3, 4, 5}; | ||
| static constexpr int expected[5] = {4, 5, 1, 2, 3}; | ||
|
|
||
| template <ranges::forward_range Read, indirectly_writable<ranges::range_reference_t<Read>> Write> | ||
| static constexpr void call() { | ||
| using ranges::rotate_copy, ranges::rotate_copy_result, ranges::equal, ranges::iterator_t; | ||
| { // Validate iterator overload | ||
| int output[5] = {-1, -1, -1, -1, -1}; | ||
| Read wrapped_input{input}; | ||
| iterator_t<Read> mid = next(wrapped_input.begin(), 3); | ||
|
|
||
| auto result = rotate_copy(wrapped_input.begin(), mid, wrapped_input.end(), Write{output}); | ||
| STATIC_ASSERT(same_as<decltype(result), rotate_copy_result<iterator_t<Read>, Write>>); | ||
| assert(result.in == wrapped_input.end()); | ||
| assert(result.out.peek() == end(output)); | ||
| assert(equal(expected, output)); | ||
| } | ||
| { // Validate range overload | ||
| int output[5] = {-1, -1, -1, -1, -1}; | ||
| Read wrapped_input{input}; | ||
| iterator_t<Read> mid = next(wrapped_input.begin(), 3); | ||
|
|
||
| auto result = rotate_copy(wrapped_input, mid, Write{output}); | ||
| STATIC_ASSERT(same_as<decltype(result), rotate_copy_result<iterator_t<Read>, Write>>); | ||
| assert(result.in == wrapped_input.end()); | ||
| assert(result.out.peek() == end(output)); | ||
| assert(equal(expected, output)); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| int main() { | ||
| STATIC_ASSERT((test_fwd_write<instantiator, const int, int>(), true)); | ||
| test_fwd_write<instantiator, const int, int>(); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.