-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Implement ranges::generate and ranges::generate_n #905
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
43 commits
Select commit
Hold shift + click to select a range
19c2a15
added the move algorithm on line 1265 of algorithm and created a new …
ahanamuk 354e48b
added cmake file
ahanamuk 09f6c9f
passing all tests for ranges move algorithm
ahanamuk 61375a9
updated move algo tests to check that we actually move elems, not jus…
ahanamuk 68640ed
enabled constexpr, cleaned up move algo test
ahanamuk 5277552
removed iostream unused header
ahanamuk 45fb14d
mainly updated formatting/comments based on feedback
ahanamuk 80e349e
Delete cmake
ahanamuk d4f91b0
modified a test
ahanamuk a685197
Merge branch 'move_algo' of https://github.com/ahanamuk/STL
ahanamuk c9f134f
initial fill algo
ahanamuk 93ff947
Passing all fill tests
ahanamuk be947f1
added a test case
ahanamuk 5cb7bfc
minor changes/formatting updates to move
ahanamuk 9170077
updated clang formatting
ahanamuk d4fbaac
initial fill algo
ahanamuk 064684e
comitting untracked stuff
ahanamuk 91040f9
generate initial commit
ahanamuk dd51ae0
minor changes
ahanamuk 62689da
Merge branch 'master' into generate_algo
CaseyCarter e2c8965
generate_n tests added
ahanamuk cc7220a
similar changes as casey made in fill_n
ahanamuk f7cf046
Merge pull request #2 from CaseyCarter/generate
ahanamuk e61aa5f
generate and generate_n tests passing now
ahanamuk 9c8acb3
minor change
ahanamuk 63a57a4
improved style
ahanamuk b0fb033
added copyright banner
ahanamuk 1c7b54d
minor deindented algo
ahanamuk e13beda
tried to write a better test for generate but it threw a bunch of err…
ahanamuk b8a91e3
trimmed white space
ahanamuk 947f2dd
made the function being passed into generate be non-constant
ahanamuk c51d3a0
++i instead of i++
ahanamuk 9b579b0
Merge branch 'master' into generate_algo
CaseyCarter d954405
Run clang-format after merging.
StephanTLavavej 3bb5a62
fixed toda condition and lambda function testing
ahanamuk 8cf5aa7
Merge remote-tracking branch 'origin/master' into generate
CaseyCarter 37b38d9
tiny fixes:
CaseyCarter a985e79
added test for 0 and -1 for generate_n
ahanamuk 9756d7b
Merge remote-tracking branch 'origin/master' into generate
CaseyCarter b2d281a
Review comments; modernize
CaseyCarter 053cda7
Review comments
CaseyCarter 40ddeac
Apply suggestions from code review
CaseyCarter 81b8b70
Miya's 11th hour save
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,50 @@ | ||
| // 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; | ||
|
|
||
CaseyCarter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| constexpr auto iota_gen = [val = 0]() mutable { return val++; }; | ||
|
|
||
| // Validate dangling story | ||
| STATIC_ASSERT(same_as<decltype(ranges::generate(borrowed<false>{}, iota_gen)), ranges::dangling>); | ||
| STATIC_ASSERT(same_as<decltype(ranges::generate(borrowed<true>{}, iota_gen)), int*>); | ||
|
|
||
| struct instantiator { | ||
| template <ranges::output_range<const int&> Out> | ||
| static constexpr void call() { | ||
| using ranges::generate, ranges::iterator_t; | ||
|
|
||
| { | ||
| int output[] = {13, 42, 1367}; | ||
| Out out_wrapper{output}; | ||
| auto result = generate(out_wrapper, iota_gen); | ||
| STATIC_ASSERT(same_as<decltype(result), iterator_t<Out>>); | ||
| assert(result == out_wrapper.end()); | ||
| 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); | ||
| STATIC_ASSERT(same_as<decltype(result), iterator_t<Out>>); | ||
| assert(result == out_wrapper.end()); | ||
| for (int i = 0; i < 3; ++i) { | ||
| assert(i == output[i]); | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| int main() { | ||
| STATIC_ASSERT((test_out<instantiator, int>(), true)); | ||
| test_out<instantiator, int>(); | ||
| } | ||
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,53 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #include <algorithm> | ||
StephanTLavavej marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #include <cassert> | ||
| #include <concepts> | ||
| #include <ranges> | ||
|
|
||
| #include <range_algorithm_support.hpp> | ||
|
|
||
| using namespace std; | ||
|
|
||
| struct instantiator { | ||
| template <ranges::output_range<const int&> Out> | ||
| static constexpr void call() { | ||
| using ranges::generate_n, ranges::equal, ranges::iterator_t; | ||
|
|
||
| const auto iota_gen = [val = 0]() mutable { return val++; }; | ||
|
|
||
| { | ||
| 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<decltype(result), iterator_t<Out>>); | ||
CaseyCarter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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<decltype(result), iterator_t<Out>>); | ||
| 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<decltype(result), iterator_t<Out>>); | ||
| assert(result.peek() == output); | ||
| assert(equal(output, expected_output)); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| int main() { | ||
| STATIC_ASSERT((test_out<instantiator, int>(), true)); | ||
| test_out<instantiator, 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.