|
|
Log in / Subscribe / Register

Toward a better list iterator for the kernel

Toward a better list iterator for the kernel

Posted Mar 10, 2022 21:55 UTC (Thu) by bartoc (guest, #124262)
In reply to: Toward a better list iterator for the kernel by jengelh
Parent article: Toward a better list iterator for the kernel

Note that what the list iterator does is pretty far from how C++ iterators work. This style of iterator is "I write the loop, and I'll insert your body with the right item all set up", where C++ is "you write the loop, and ask me for each item"

There's nothing really preventing you from doing the C++ approach in C, although you need to be careful about inlining, you just write an "iterator init from structure" "iterator next" and "is iterator done" function and call them in the appropriate places in a for loop. However I think the more intrusive way of doing things is quite a lot clearer when reading the iterator implementation, esp for more complicated iterators.


to post comments


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds