summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorVitaly Dyachkov <obyknovenius@me.com>2022-04-12 19:21:05 +0200
committerLinus Groh <mail@linusgroh.de>2022-05-08 17:02:00 +0200
commita0a4d169f47e03802b885bf16c997281313ec8e1 (patch)
tree659a76d6a2e34fdab8207fb044b4ad3eef1b0773 /AK
parent6ed2ded77c2c56b26d3b33a037b5fd2deee74148 (diff)
downloadserenity-a0a4d169f47e03802b885bf16c997281313ec8e1.zip
AK+LibGUI: Pass predicate to *_matching() methods by const reference
Diffstat (limited to 'AK')
-rw-r--r--AK/HashMap.h2
-rw-r--r--AK/HashTable.h2
-rw-r--r--AK/Vector.h14
3 files changed, 9 insertions, 9 deletions
diff --git a/AK/HashMap.h b/AK/HashMap.h
index 50abecd638..4d61cede6a 100644
--- a/AK/HashMap.h
+++ b/AK/HashMap.h
@@ -77,7 +77,7 @@ public:
}
template<typename TUnaryPredicate>
- bool remove_all_matching(TUnaryPredicate predicate)
+ bool remove_all_matching(TUnaryPredicate const& predicate)
{
return m_table.template remove_all_matching([&](auto& entry) {
return predicate(entry.key, entry.value);
diff --git a/AK/HashTable.h b/AK/HashTable.h
index 14478b4701..c9cfbabfa9 100644
--- a/AK/HashTable.h
+++ b/AK/HashTable.h
@@ -422,7 +422,7 @@ public:
}
template<typename TUnaryPredicate>
- bool remove_all_matching(TUnaryPredicate predicate)
+ bool remove_all_matching(TUnaryPredicate const& predicate)
{
size_t removed_count = 0;
for (size_t i = 0; i < m_capacity; ++i) {
diff --git a/AK/Vector.h b/AK/Vector.h
index a68628282e..c56761e369 100644
--- a/AK/Vector.h
+++ b/AK/Vector.h
@@ -163,7 +163,7 @@ public:
VisibleType& last() { return at(size() - 1); }
template<typename TUnaryPredicate>
- Optional<VisibleType&> first_matching(TUnaryPredicate predicate) requires(!contains_reference)
+ Optional<VisibleType&> first_matching(TUnaryPredicate const& predicate) requires(!contains_reference)
{
for (size_t i = 0; i < size(); ++i) {
if (predicate(at(i))) {
@@ -174,7 +174,7 @@ public:
}
template<typename TUnaryPredicate>
- Optional<VisibleType const&> first_matching(TUnaryPredicate predicate) const requires(!contains_reference)
+ Optional<VisibleType const&> first_matching(TUnaryPredicate const& predicate) const requires(!contains_reference)
{
for (size_t i = 0; i < size(); ++i) {
if (predicate(at(i))) {
@@ -185,7 +185,7 @@ public:
}
template<typename TUnaryPredicate>
- Optional<VisibleType&> last_matching(TUnaryPredicate predicate) requires(!contains_reference)
+ Optional<VisibleType&> last_matching(TUnaryPredicate const& predicate) requires(!contains_reference)
{
for (ssize_t i = size() - 1; i >= 0; --i) {
if (predicate(at(i))) {
@@ -233,7 +233,7 @@ public:
}
template<typename TUnaryPredicate, typename U = T>
- void insert_before_matching(U&& value, TUnaryPredicate predicate, size_t first_index = 0, size_t* inserted_index = nullptr) requires(CanBePlacedInsideVector<U>)
+ void insert_before_matching(U&& value, TUnaryPredicate const& predicate, size_t first_index = 0, size_t* inserted_index = nullptr) requires(CanBePlacedInsideVector<U>)
{
MUST(try_insert_before_matching(forward<U>(value), predicate, first_index, inserted_index));
}
@@ -415,7 +415,7 @@ public:
}
template<typename TUnaryPredicate>
- bool remove_first_matching(TUnaryPredicate predicate)
+ bool remove_first_matching(TUnaryPredicate const& predicate)
{
for (size_t i = 0; i < size(); ++i) {
if (predicate(at(i))) {
@@ -427,7 +427,7 @@ public:
}
template<typename TUnaryPredicate>
- bool remove_all_matching(TUnaryPredicate predicate)
+ bool remove_all_matching(TUnaryPredicate const& predicate)
{
bool something_was_removed = false;
for (size_t i = 0; i < size();) {
@@ -507,7 +507,7 @@ public:
}
template<typename TUnaryPredicate, typename U = T>
- ErrorOr<void> try_insert_before_matching(U&& value, TUnaryPredicate predicate, size_t first_index = 0, size_t* inserted_index = nullptr) requires(CanBePlacedInsideVector<U>)
+ ErrorOr<void> try_insert_before_matching(U&& value, TUnaryPredicate const& predicate, size_t first_index = 0, size_t* inserted_index = nullptr) requires(CanBePlacedInsideVector<U>)
{
for (size_t i = first_index; i < size(); ++i) {
if (predicate(at(i))) {