Skip to content

Add tree traversal with callbacks

Carsten Gräser requested to merge feature/add-callback-traversal into master

This simplifies traversing trees in many cases because one can write classic "loops" by using lambdas as callbacks, e.g.,

int i=0;
forEachNode(tree, [](auto&&...) {
  ++i;
});

Notice that there is no need to use std::forward() in the new functions: Neither the tree nor the callbacks are stored by value. Hence there is no need to forward them as r-value references. Instead the CallbackVisitor stores references to functions. This is OK, because it does not outlive the forEach*() call such that it's safe to pass temporaries.

Edited by Carsten Gräser

Merge request reports