mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:57:45 +00:00
Vector: Homogenize type and parameter names for predicates
This commit is contained in:
parent
334499a3f4
commit
de7831153f
1 changed files with 18 additions and 18 deletions
36
AK/Vector.h
36
AK/Vector.h
|
@ -163,22 +163,22 @@ public:
|
||||||
T const& last() const { return at(size() - 1); }
|
T const& last() const { return at(size() - 1); }
|
||||||
T& last() { return at(size() - 1); }
|
T& last() { return at(size() - 1); }
|
||||||
|
|
||||||
template<typename Callback>
|
template<typename TUnaryPredicate>
|
||||||
Optional<T> first_matching(Callback callback)
|
Optional<T> first_matching(TUnaryPredicate predicate)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < size(); ++i) {
|
for (size_t i = 0; i < size(); ++i) {
|
||||||
if (callback(at(i))) {
|
if (predicate(at(i))) {
|
||||||
return at(i);
|
return at(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Callback>
|
template<typename TUnaryPredicate>
|
||||||
Optional<T> last_matching(Callback callback)
|
Optional<T> last_matching(TUnaryPredicate predicate)
|
||||||
{
|
{
|
||||||
for (ssize_t i = size() - 1; i >= 0; --i) {
|
for (ssize_t i = size() - 1; i >= 0; --i) {
|
||||||
if (callback(at(i))) {
|
if (predicate(at(i))) {
|
||||||
return at(i);
|
return at(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -220,10 +220,10 @@ public:
|
||||||
VERIFY(did_allocate);
|
VERIFY(did_allocate);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename C, typename U = T>
|
template<typename TUnaryPredicate, typename U = T>
|
||||||
void insert_before_matching(U&& value, C callback, size_t first_index = 0, size_t* inserted_index = nullptr) requires(CanBePlacedInsideVector<U>)
|
void insert_before_matching(U&& value, TUnaryPredicate predicate, size_t first_index = 0, size_t* inserted_index = nullptr) requires(CanBePlacedInsideVector<U>)
|
||||||
{
|
{
|
||||||
auto did_allocate = try_insert_before_matching(forward<U>(value), callback, first_index, inserted_index);
|
auto did_allocate = try_insert_before_matching(forward<U>(value), predicate, first_index, inserted_index);
|
||||||
VERIFY(did_allocate);
|
VERIFY(did_allocate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,11 +397,11 @@ public:
|
||||||
m_size -= count;
|
m_size -= count;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Callback>
|
template<typename TUnaryPredicate>
|
||||||
bool remove_first_matching(Callback callback)
|
bool remove_first_matching(TUnaryPredicate predicate)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < size(); ++i) {
|
for (size_t i = 0; i < size(); ++i) {
|
||||||
if (callback(at(i))) {
|
if (predicate(at(i))) {
|
||||||
remove(i);
|
remove(i);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -409,11 +409,11 @@ public:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Callback>
|
template<typename TUnaryPredicate>
|
||||||
void remove_all_matching(Callback callback)
|
void remove_all_matching(TUnaryPredicate predicate)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < size();) {
|
for (size_t i = 0; i < size();) {
|
||||||
if (callback(at(i))) {
|
if (predicate(at(i))) {
|
||||||
remove(i);
|
remove(i);
|
||||||
} else {
|
} else {
|
||||||
++i;
|
++i;
|
||||||
|
@ -487,11 +487,11 @@ public:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename C, typename U = T>
|
template<typename TUnaryPredicate, typename U = T>
|
||||||
[[nodiscard]] bool try_insert_before_matching(U&& value, C callback, size_t first_index = 0, size_t* inserted_index = nullptr) requires(CanBePlacedInsideVector<U>)
|
[[nodiscard]] bool try_insert_before_matching(U&& value, TUnaryPredicate predicate, size_t first_index = 0, size_t* inserted_index = nullptr) requires(CanBePlacedInsideVector<U>)
|
||||||
{
|
{
|
||||||
for (size_t i = first_index; i < size(); ++i) {
|
for (size_t i = first_index; i < size(); ++i) {
|
||||||
if (callback(at(i))) {
|
if (predicate(at(i))) {
|
||||||
if (!try_insert(i, forward<U>(value)))
|
if (!try_insert(i, forward<U>(value)))
|
||||||
return false;
|
return false;
|
||||||
if (inserted_index)
|
if (inserted_index)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue