diff --git a/repos/base/include/util/list_model.h b/repos/base/include/util/list_model.h index 3a4b043f30..5f950ac6d1 100644 --- a/repos/base/include/util/list_model.h +++ b/repos/base/include/util/list_model.h @@ -22,6 +22,7 @@ /* Genode includes */ #include #include +#include namespace Genode { template class List_model; } @@ -94,6 +95,21 @@ class Genode::List_model } } + /** + * Apply functor 'fn' to the first element of the list model + * + * Using this method combined with the 'Element::next' method, the list + * model can be traversed manually. This is handy in situations where + * the list-model elements are visited via recursive function calls + * instead of a 'for_each' loop. + */ + template + void apply_first(FN const &fn) const + { + if (Element const *e = _elements.first()) + fn(static_cast(*e)); + } + /** * Remove all elements from the data model *