-
Notifications
You must be signed in to change notification settings - Fork 118
Add ranges::find_last* #2667
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
Add ranges::find_last* #2667
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
61e47a7
Fix stable references to the C++ standard
akukanov e8b7196
Add ranges::find_last_if
akukanov 6efa590
Add the test for find_last_if
akukanov 1ff7497
Improve diagnostics for a wrong result subrange
akukanov 62d0a9c
Correctly get the base iterator from reverse_iterator
akukanov aa76282
Improve the test
akukanov 628fb98
Add ranges::find_last, ranges::find_last_if_not
akukanov ba194e3
Add two new tests
akukanov e3ae592
Improve formatting
akukanov 17a8fca
Do not forward the input range
akukanov 7449204
Merge changes from 'main'
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // -*- C++ -*- | ||
| //===------------------------------------------------------===// | ||
| // | ||
| // Copyright (C) UXL Foundation Contributors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===------------------------------------------------------===// | ||
|
|
||
| #include "std_ranges_test.h" | ||
|
|
||
| #if _ENABLE_STD_RANGES_TESTING | ||
| #if __cpp_lib_ranges_find_last >= 202207L | ||
| auto checker = TEST_PREPARE_CALLABLE(std::ranges::find_last); | ||
| #else | ||
| struct { | ||
| template<std::ranges::forward_range R, typename T, typename Proj = std::identity> | ||
| std::ranges::borrowed_subrange_t<R> operator()(R&& r, const T& val, Proj proj = {}) | ||
| { | ||
| std::ranges::iterator_t<R> res{}, it{}; | ||
| bool found = false; | ||
| for (it = std::ranges::begin(r); it != std::ranges::end(r); ++it) | ||
| { | ||
| if (std::invoke(proj, *it) == val) | ||
| { | ||
| res = it; | ||
| found = true; | ||
| } | ||
| } | ||
| return {found? res : it, it}; | ||
| } | ||
| } checker; | ||
| #endif | ||
| #endif | ||
|
|
||
| std::int32_t | ||
| main() | ||
| { | ||
| #if _ENABLE_STD_RANGES_TESTING | ||
| using namespace test_std_ranges; | ||
| namespace dpl_ranges = oneapi::dpl::ranges; | ||
|
|
||
| test_range_algo<0>{big_sz}(dpl_ranges::find_last, checker, 314); | ||
| test_range_algo<1>{}(dpl_ranges::find_last, checker, 271, proj); | ||
| test_range_algo<2, P2>{}(dpl_ranges::find_last, checker, 99, &P2::x); | ||
| test_range_algo<3, P2>{}(dpl_ranges::find_last, checker, -359, &P2::proj); // not found | ||
| #endif //_ENABLE_STD_RANGES_TESTING | ||
|
|
||
| return TestUtils::done(_ENABLE_STD_RANGES_TESTING); | ||
| } |
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 @@ | ||
| // -*- C++ -*- | ||
| //===------------------------------------------------------===// | ||
| // | ||
| // Copyright (C) UXL Foundation Contributors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===------------------------------------------------------===// | ||
|
|
||
| #include "std_ranges_test.h" | ||
|
|
||
| #if _ENABLE_STD_RANGES_TESTING | ||
| #if __cpp_lib_ranges_find_last >= 202207L | ||
| auto checker = TEST_PREPARE_CALLABLE(std::ranges::find_last_if); | ||
| #else | ||
| struct { | ||
| template<std::ranges::forward_range R, typename Pred, typename Proj = std::identity> | ||
| std::ranges::borrowed_subrange_t<R> operator()(R&& r, Pred pred, Proj proj = {}) | ||
| { | ||
| std::ranges::iterator_t<R> res{}, it{}; | ||
| bool found = false; | ||
| for (it = std::ranges::begin(r); it != std::ranges::end(r); ++it) | ||
| { | ||
| if (bool(std::invoke(pred, std::invoke(proj, *it)))) | ||
| { | ||
| res = it; | ||
| found = true; | ||
| } | ||
| } | ||
| return {found? res : it, it}; | ||
| } | ||
| } checker; | ||
| #endif | ||
| #endif | ||
|
|
||
| std::int32_t | ||
| main() | ||
| { | ||
| #if _ENABLE_STD_RANGES_TESTING | ||
| using namespace test_std_ranges; | ||
| namespace dpl_ranges = oneapi::dpl::ranges; | ||
|
|
||
| auto less397 = [](auto&& val) { return val < 397; }; | ||
|
|
||
| test_range_algo<0>{big_sz}(dpl_ranges::find_last_if, checker, pred); | ||
| test_range_algo<1>{}(dpl_ranges::find_last_if, checker, less397, proj); | ||
| test_range_algo<2, P2>{}(dpl_ranges::find_last_if, checker, pred3, &P2::x); // not found | ||
| test_range_algo<3, P2>{}(dpl_ranges::find_last_if, checker, pred, &P2::proj); | ||
| #endif //_ENABLE_STD_RANGES_TESTING | ||
|
|
||
| return TestUtils::done(_ENABLE_STD_RANGES_TESTING); | ||
| } |
52 changes: 52 additions & 0 deletions
52
test/parallel_api/ranges/std_ranges_find_last_if_not.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,52 @@ | ||
| // -*- C++ -*- | ||
| //===------------------------------------------------------===// | ||
| // | ||
| // Copyright (C) UXL Foundation Contributors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===------------------------------------------------------===// | ||
|
|
||
| #include "std_ranges_test.h" | ||
|
|
||
| #if _ENABLE_STD_RANGES_TESTING | ||
| #if __cpp_lib_ranges_find_last >= 202207L | ||
| auto checker = TEST_PREPARE_CALLABLE(std::ranges::find_last_if_not); | ||
| #else | ||
| struct { | ||
| template<std::ranges::forward_range R, typename Pred, typename Proj = std::identity> | ||
| std::ranges::borrowed_subrange_t<R> operator()(R&& r, Pred pred, Proj proj = {}) | ||
| { | ||
| std::ranges::iterator_t<R> res{}, it{}; | ||
| bool found = false; | ||
| for (it = std::ranges::begin(r); it != std::ranges::end(r); ++it) | ||
| { | ||
| if (!bool(std::invoke(pred, std::invoke(proj, *it)))) | ||
| { | ||
| res = it; | ||
| found = true; | ||
| } | ||
| } | ||
| return {found? res : it, it}; | ||
| } | ||
| } checker; | ||
| #endif | ||
| #endif | ||
|
|
||
| std::int32_t | ||
| main() | ||
| { | ||
| #if _ENABLE_STD_RANGES_TESTING | ||
| using namespace test_std_ranges; | ||
| namespace dpl_ranges = oneapi::dpl::ranges; | ||
|
|
||
| auto less397 = [](auto&& val) { return val < 397; }; | ||
|
|
||
| test_range_algo<0>{big_sz}(dpl_ranges::find_last_if_not, checker, less397); | ||
| test_range_algo<1>{}(dpl_ranges::find_last_if_not, checker, less397, proj); | ||
| test_range_algo<2, P2>{}(dpl_ranges::find_last_if_not, checker, pred1, &P2::x); // not found | ||
| test_range_algo<3, P2>{}(dpl_ranges::find_last_if_not, checker, less397, &P2::proj); | ||
| #endif //_ENABLE_STD_RANGES_TESTING | ||
|
|
||
| return TestUtils::done(_ENABLE_STD_RANGES_TESTING); | ||
| } |
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
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.