AK+LibGUI: Pass predicate to *_matching() methods by const reference

This commit is contained in:
Vitaly Dyachkov 2022-04-12 19:21:05 +02:00 committed by Linus Groh
parent 6ed2ded77c
commit a0a4d169f4
5 changed files with 12 additions and 12 deletions

View file

@ -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);

View file

@ -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) {

View file

@ -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))) {

View file

@ -10,9 +10,9 @@
namespace GUI {
void ModelSelection::remove_all_matching(Function<bool(ModelIndex const&)> filter)
void ModelSelection::remove_all_matching(Function<bool(ModelIndex const&)> const& filter)
{
if (m_indices.remove_all_matching([&](ModelIndex const& index) { return filter(index); }))
if (m_indices.remove_all_matching(filter))
notify_selection_changed();
}

View file

@ -76,7 +76,7 @@ public:
return *m_indices.begin();
}
void remove_all_matching(Function<bool(ModelIndex const&)> filter);
void remove_all_matching(Function<bool(ModelIndex const&)> const& filter);
template<typename Function>
void change_from_model(Badge<SortingProxyModel>, Function f)