mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-06 07:48:38 +09:00
Issue #2142 - Add predicate functions count_if and any_of to ListNode iterator
This commit is contained in:
parent
627d0da7dc
commit
3b9b111b2f
1 changed files with 22 additions and 0 deletions
|
|
@ -6,6 +6,8 @@
|
|||
#ifndef frontend_ParseNode_h
|
||||
#define frontend_ParseNode_h
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
|
||||
#include "builtin/ModuleObject.h"
|
||||
|
|
@ -1420,6 +1422,8 @@ class ListNode : public ParseNode
|
|||
}
|
||||
};
|
||||
|
||||
typedef std::function<bool(ParseNode*)> predicate_fun;
|
||||
|
||||
#ifdef DEBUG
|
||||
MOZ_MUST_USE bool contains(ParseNode* target) const {
|
||||
MOZ_ASSERT(target);
|
||||
|
|
@ -1460,6 +1464,24 @@ class ListNode : public ParseNode
|
|||
MOZ_ASSERT_IF(end, contains(end));
|
||||
return range(head(), end);
|
||||
}
|
||||
|
||||
// Predicate functions, like their counterparts in C++17
|
||||
size_t count_if(predicate_fun predicate) const {
|
||||
size_t count = 0;
|
||||
for (ParseNode* node = head(); node; node = node->pn_next) {
|
||||
if (predicate(node))
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
bool any_of(predicate_fun predicate) const {
|
||||
for (ParseNode* node = head(); node; node = node->pn_next) {
|
||||
if (predicate(node))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
inline bool
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue