mirror of
https://github.com/espressif/openthread.git
synced 2026-08-20 17:39:51 +00:00
[linked-list] range-based for loop iteration over all entries (#6945)
This commit enables use of range-based `for` loop for iterating over all the entries in a `LinkedList`. It adds private implementations of `Iterator` and `ConstIterator` which inherit from `ItemPtrIterator` and use the `GetNext()` to go to the next entry. The range-based `for` loop practically acts as a syntactic sugar helping simplify the code and does not add any code size (or any expected run-time) overhead.
This commit is contained in:
@@ -74,11 +74,11 @@ void VerifyLinkedListContent(const ot::LinkedList<Entry> *aList, ...)
|
||||
|
||||
va_start(args, aList);
|
||||
|
||||
for (const Entry *entry = aList->GetHead(); entry; entry = entry->GetNext())
|
||||
for (const Entry &entry : *aList)
|
||||
{
|
||||
argEntry = va_arg(args, Entry *);
|
||||
VerifyOrQuit(argEntry != nullptr, "List contains more entries than expected");
|
||||
VerifyOrQuit(argEntry == entry, "List does not contain the same entry");
|
||||
VerifyOrQuit(argEntry == &entry, "List does not contain the same entry");
|
||||
VerifyOrQuit(aList->Contains(*argEntry));
|
||||
VerifyOrQuit(aList->ContainsMatching(argEntry->GetName()));
|
||||
VerifyOrQuit(aList->ContainsMatching(argEntry->GetId()));
|
||||
|
||||
Reference in New Issue
Block a user