[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:
Abtin Keshavarzian
2021-08-23 14:50:14 -07:00
committed by GitHub
parent 34366834b0
commit 6895edda59
21 changed files with 241 additions and 197 deletions
+2 -2
View File
@@ -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()));