mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:27:45 +00:00
AK: Add Vector::insert_before_matching(T&&, callback);
This allows you to do things like: vector.insert_before_matching(value, [](auto& entry) { return value < entry; }); Basically it scans until it finds an element that matches the condition callback and then inserts the new value before the matching element.
This commit is contained in:
parent
57da8792fd
commit
55a5c46253
3 changed files with 47 additions and 0 deletions
|
@ -41,5 +41,21 @@ int main()
|
|||
}
|
||||
EXPECT_EQ(loop_counter, 2);
|
||||
|
||||
{
|
||||
Vector<String> strings;
|
||||
strings.append("abc");
|
||||
strings.append("def");
|
||||
strings.append("ghi");
|
||||
|
||||
strings.insert_before_matching("f-g", [](auto& entry) {
|
||||
return "f-g" < entry;
|
||||
});
|
||||
|
||||
EXPECT_EQ(strings[0], "abc");
|
||||
EXPECT_EQ(strings[1], "def");
|
||||
EXPECT_EQ(strings[2], "f-g");
|
||||
EXPECT_EQ(strings[3], "ghi");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue