-
Notifications
You must be signed in to change notification settings - Fork 117
Add ranges::replace_copy[_if] #2666
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
14 commits
Select commit
Hold shift + click to select a range
544c5a3
Redirect all variations of replace_copy_if to transform
akukanov 4de7c89
Add the implementation of ranges::replace_copy[_if]
akukanov a22d30e
Improve formatting
akukanov 35d24dc
Add tests
akukanov 0140268
Fix the use of std::ranges::min
akukanov 0404d51
Add missed new value arguments
akukanov acdc14d
Change file headers
akukanov 805aa7c
Add forward declarations
akukanov 9602975
Revert redirection of replace_copy_if to transform
akukanov 08deb92
Adjust code in the algorithm_ranges_* pattern files
akukanov 725e1c2
Change the implementation of replace_copy_if
akukanov ed1f8eb
Merge changes from 'main'
akukanov 269e48c
Fix compilation
akukanov 99615d4
Formatting
akukanov 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
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,42 @@ | ||
| // -*- C++ -*- | ||
| //===------------------------------------------------------===// | ||
| // | ||
| // Copyright (C) UXL Foundation Contributors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===------------------------------------------------------===// | ||
|
|
||
| #include "std_ranges_test.h" | ||
|
|
||
| std::int32_t | ||
| main() | ||
| { | ||
| #if _ENABLE_STD_RANGES_TESTING | ||
| using namespace test_std_ranges; | ||
| namespace dpl_ranges = oneapi::dpl::ranges; | ||
|
|
||
| //A checker below modifies a return type; a range based version with policy has another return type. | ||
| auto replace_copy_checker = [](std::ranges::random_access_range auto&& r_in, | ||
| std::ranges::random_access_range auto&& r_out, auto&&... args) | ||
| { | ||
| using Size = std::common_type_t<std::ranges::range_size_t<decltype(r_in)>, | ||
| std::ranges::range_size_t<decltype(r_out)>>; | ||
| Size size = std::ranges::min(std::ranges::size(r_in), std::ranges::size(r_out)); | ||
|
|
||
| std::ranges::replace_copy(std::ranges::take_view(r_in, size), std::ranges::begin(r_out), | ||
| std::forward<decltype(args)>(args)...); | ||
|
|
||
| using ret_type = std::ranges::replace_copy_result<std::ranges::borrowed_iterator_t<decltype(r_in)>, | ||
| std::ranges::borrowed_iterator_t<decltype(r_out)>>; | ||
| return ret_type{std::ranges::begin(r_in) + size, std::ranges::begin(r_out) + size}; | ||
| }; | ||
|
|
||
| test_range_algo<0, int, data_in_out_lim>{big_sz}(dpl_ranges::replace_copy, replace_copy_checker, 273, -13); | ||
| test_range_algo<1, int, data_in_out_lim>{}(dpl_ranges::replace_copy, replace_copy_checker, 91, -189, proj); | ||
| test_range_algo<2, P2, data_in_out_lim>{}(dpl_ranges::replace_copy, replace_copy_checker, 5, -43, &P2::x); | ||
| test_range_algo<3, P2, data_in_out_lim>{}(dpl_ranges::replace_copy, replace_copy_checker, 117, -7, &P2::proj); | ||
| #endif //_ENABLE_STD_RANGES_TESTING | ||
|
|
||
| return TestUtils::done(_ENABLE_STD_RANGES_TESTING); | ||
| } |
42 changes: 42 additions & 0 deletions
42
test/parallel_api/ranges/std_ranges_replace_copy_if.pass.cpp
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,42 @@ | ||
| // -*- C++ -*- | ||
| //===------------------------------------------------------===// | ||
| // | ||
| // Copyright (C) UXL Foundation Contributors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===------------------------------------------------------===// | ||
|
|
||
| #include "std_ranges_test.h" | ||
|
|
||
| std::int32_t | ||
| main() | ||
| { | ||
| #if _ENABLE_STD_RANGES_TESTING | ||
| using namespace test_std_ranges; | ||
| namespace dpl_ranges = oneapi::dpl::ranges; | ||
|
|
||
| //A checker below modifies a return type; a range based version with policy has another return type. | ||
| auto replace_copy_if_checker = [](std::ranges::random_access_range auto&& r_in, | ||
| std::ranges::random_access_range auto&& r_out, auto&&... args) | ||
| { | ||
| using Size = std::common_type_t<std::ranges::range_size_t<decltype(r_in)>, | ||
| std::ranges::range_size_t<decltype(r_out)>>; | ||
| Size size = std::ranges::min(std::ranges::size(r_in), std::ranges::size(r_out)); | ||
|
|
||
| std::ranges::replace_copy_if(std::ranges::take_view(r_in, size), std::ranges::begin(r_out), | ||
| std::forward<decltype(args)>(args)...); | ||
|
|
||
| using ret_type = std::ranges::replace_copy_if_result<std::ranges::borrowed_iterator_t<decltype(r_in)>, | ||
| std::ranges::borrowed_iterator_t<decltype(r_out)>>; | ||
| return ret_type{std::ranges::begin(r_in) + size, std::ranges::begin(r_out) + size}; | ||
| }; | ||
|
|
||
| test_range_algo<0, int, data_in_out_lim>{big_sz}(dpl_ranges::replace_copy_if, replace_copy_if_checker, pred, -29); | ||
| test_range_algo<1, int, data_in_out_lim>{}(dpl_ranges::replace_copy_if, replace_copy_if_checker, pred1, -277, proj); | ||
| test_range_algo<2, P2, data_in_out_lim>{}(dpl_ranges::replace_copy_if, replace_copy_if_checker, pred2, -43, &P2::x); | ||
| test_range_algo<3, P2, data_in_out_lim>{}(dpl_ranges::replace_copy_if, replace_copy_if_checker, pred3, -817, &P2::proj); | ||
|
Comment on lines
+35
to
+38
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A case with different types of |
||
| #endif //_ENABLE_STD_RANGES_TESTING | ||
|
|
||
| return TestUtils::done(_ENABLE_STD_RANGES_TESTING); | ||
| } | ||
Oops, something went wrong.
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.