mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-27 12:46:06 +00:00
AK: Add an AK::find
helper to return a reference to the found value
This is often more convenient than dealing with iterators. This commit includes a couple conversions to find_value as examples.
This commit is contained in:
parent
9cab5dc0c9
commit
7f37a8f60f
Notes:
github-actions[bot]
2025-04-06 11:46:22 +00:00
Author: https://github.com/trflynn89
Commit: 7f37a8f60f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4237
5 changed files with 34 additions and 30 deletions
|
@ -51,3 +51,14 @@ TEST_CASE(should_return_index_to_first_predicate_matching_value_in_container)
|
|||
|
||||
EXPECT(4 == AK::find_index(a.begin(), a.end(), 0));
|
||||
}
|
||||
|
||||
TEST_CASE(find_value)
|
||||
{
|
||||
static constexpr Array array { 1, 2, 3, 4, 0, 6, 7, 8, 0, 0 };
|
||||
|
||||
auto value = find_value(array, [](auto value) { return value > 5; });
|
||||
EXPECT_EQ(value, 6);
|
||||
|
||||
value = find_value(array, [](auto value) { return value == 12389; });
|
||||
EXPECT(!value.has_value());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue