-
Notifications
You must be signed in to change notification settings - Fork 117
Add ranges::{starts,ends}_with #2618
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
12 commits
Select commit
Hold shift + click to select a range
17cc30c
Add ranges::{starts,ends}_with
akukanov 9d31fcd
Add tests for ranges::{starts,ends}_with
akukanov 7cbc809
Formatting
akukanov 7a76f6c
Remove duplicate header inclusion
akukanov 2c03e91
Address the review feedback
akukanov cfe72b5
Add a workaround for an issue in libstdc++ 10
akukanov 4b2d9a8
Formatting
akukanov c8cd40e
Use forward declarations to slightly simplify code structure
akukanov 0be6f8f
Formatting
akukanov 8dbb05b
Merge changes from 'main'
akukanov 57a6bea
Address review feedback
akukanov 78095e1
Address the review feedback
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
Some comments aren't visible on the classic Files Changed page.
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,52 @@ | ||
| // -*- C++ -*- | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Copyright (C) 2026 UXL Foundation Contributors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "std_ranges_test.h" | ||
|
|
||
| #if _ENABLE_STD_RANGES_TESTING | ||
| template<int call_id, typename T, typename DataGen2 = std::identity> | ||
| using launcher = test_std_ranges::test_range_algo<call_id, T, test_std_ranges::data_in_in, | ||
| /*DataGen1*/ std::identity, DataGen2>; | ||
| #if __cpp_lib_ranges_starts_ends_with >= 202106L | ||
| auto checker = TEST_PREPARE_CALLABLE(std::ranges::ends_with); | ||
| #else | ||
| struct { | ||
| template<std::ranges::input_range R1, std::ranges::input_range R2, typename Pred = std::ranges::equal_to, | ||
| typename Proj1 = std::identity, typename Proj2 = std::identity> | ||
| bool operator()(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) | ||
| { | ||
| std::ranges::reverse_view r2_reverse{r2}; | ||
| auto last = r2_reverse.end(); | ||
| return std::ranges::mismatch(std::ranges::reverse_view(r1), r2_reverse, pred, proj1, proj2).in2 == last; | ||
| } | ||
| } checker; | ||
| #endif | ||
| #endif | ||
|
|
||
| std::int32_t | ||
| main() | ||
| { | ||
| #if _ENABLE_STD_RANGES_TESTING | ||
| using namespace test_std_ranges; | ||
| namespace dpl_ranges = oneapi::dpl::ranges; | ||
|
|
||
| using data_gen_shift_med = decltype([](auto i){ return i + medium_size/2; }); | ||
| using data_gen_shift_big = decltype([](auto i){ return i + big_size/2; }); | ||
|
|
||
| launcher<0, int>{big_sz}(dpl_ranges::ends_with, checker, binary_pred_const); | ||
| launcher<1, int>{}(dpl_ranges::ends_with, checker, binary_pred, proj); | ||
| launcher<2, int, decltype(proj)>{}(dpl_ranges::ends_with, checker, binary_pred, proj); | ||
| launcher<3, P2>{}(dpl_ranges::ends_with, checker, binary_pred_const, &P2::x, &P2::proj); | ||
| launcher<4, P2>{}(dpl_ranges::ends_with, checker, binary_pred, &P2::proj, &P2::x); | ||
| launcher<5, int, data_gen_shift_med>{}(dpl_ranges::ends_with, checker); | ||
| launcher<6, int, data_gen_shift_big>{big_sz}(dpl_ranges::ends_with, checker); | ||
| #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,50 @@ | ||
| // -*- C++ -*- | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Copyright (C) 2026 UXL Foundation Contributors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "std_ranges_test.h" | ||
|
|
||
| #if _ENABLE_STD_RANGES_TESTING | ||
| template<int call_id, typename T, typename DataGen2 = std::identity> | ||
| using launcher = test_std_ranges::test_range_algo<call_id, T, test_std_ranges::data_in_in, | ||
| /*DataGen1*/ std::identity, DataGen2>; | ||
| #if __cpp_lib_ranges_starts_ends_with >= 202106L | ||
| auto checker = TEST_PREPARE_CALLABLE(std::ranges::starts_with); | ||
| #else | ||
| struct { | ||
| template<std::ranges::input_range R1, std::ranges::input_range R2, typename Pred = std::ranges::equal_to, | ||
| typename Proj1 = std::identity, typename Proj2 = std::identity> | ||
| bool operator()(R1&& r1, R2&& r2, Pred pred = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) | ||
| { | ||
| auto last = std::ranges::end(r2); | ||
| return std::ranges::mismatch(r1, r2, pred, proj1, proj2).in2 == last; | ||
| } | ||
| } checker; | ||
| #endif | ||
| #endif | ||
|
|
||
| std::int32_t | ||
| main() | ||
| { | ||
| #if _ENABLE_STD_RANGES_TESTING | ||
| using namespace test_std_ranges; | ||
| namespace dpl_ranges = oneapi::dpl::ranges; | ||
|
|
||
| auto almost_always_i = [](auto i){ return (i == medium_size/2 + 19)? 0 : i; }; | ||
| using data_gen_needle = decltype(almost_always_i); | ||
|
|
||
| launcher<0, int>{big_sz}(dpl_ranges::starts_with, checker, binary_pred_const); | ||
| launcher<1, int>{}(dpl_ranges::starts_with, checker, binary_pred, proj); | ||
| launcher<2, int, decltype(proj)>{}(dpl_ranges::starts_with, checker, binary_pred, proj); | ||
| launcher<3, P2>{}(dpl_ranges::starts_with, checker, binary_pred_const, &P2::x, &P2::proj); | ||
| launcher<4, P2>{}(dpl_ranges::starts_with, checker, binary_pred, &P2::proj, &P2::x); | ||
| launcher<5, int, data_gen_needle>{}(dpl_ranges::starts_with, checker); | ||
| #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.