mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:07:45 +00:00
AK: Make Vector<T>::{first,last}_matching() return Optional<T&>
These functions are _very_ misleading, as `first()` and `last()` return references, but `{first,last}_matching()` return copies of the values. This commit makes it so that they now return Optional<T&>, eliminating the copy and the confusion.
This commit is contained in:
parent
33e27c545e
commit
188207ed79
1 changed files with 2 additions and 2 deletions
|
@ -163,7 +163,7 @@ public:
|
||||||
VisibleType& last() { return at(size() - 1); }
|
VisibleType& last() { return at(size() - 1); }
|
||||||
|
|
||||||
template<typename TUnaryPredicate>
|
template<typename TUnaryPredicate>
|
||||||
Optional<VisibleType> first_matching(TUnaryPredicate predicate) requires(!contains_reference)
|
Optional<VisibleType&> first_matching(TUnaryPredicate predicate) requires(!contains_reference)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < size(); ++i) {
|
for (size_t i = 0; i < size(); ++i) {
|
||||||
if (predicate(at(i))) {
|
if (predicate(at(i))) {
|
||||||
|
@ -174,7 +174,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename TUnaryPredicate>
|
template<typename TUnaryPredicate>
|
||||||
Optional<VisibleType> last_matching(TUnaryPredicate predicate) requires(!contains_reference)
|
Optional<VisibleType&> last_matching(TUnaryPredicate predicate) requires(!contains_reference)
|
||||||
{
|
{
|
||||||
for (ssize_t i = size() - 1; i >= 0; --i) {
|
for (ssize_t i = size() - 1; i >= 0; --i) {
|
||||||
if (predicate(at(i))) {
|
if (predicate(at(i))) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue