version 0.4.1
traversal.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2021-2024 The Ikarus Developers mueller@ibb.uni-stuttgart.de
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
9#pragma once
10
11namespace Ikarus::utils {
12
29template <class T, class TreePath, class PowerFunc, class LeafFunc>
30void forEachLeafOrPowerLeafNode(T&& tree, TreePath&& treePath, PowerFunc&& powerFunc, LeafFunc&& leafFunc) {
31 using Tree = std::decay_t<T>;
32 if constexpr (Tree::isLeaf) {
33 leafFunc(tree, treePath);
34 } else if constexpr (Tree::isPower) {
35 if constexpr (Tree::template Child<Dune::Indices::_0>::Type::isLeaf) {
36 powerFunc(tree, treePath);
37 } else {
38 for (std::size_t i = 0; i < tree.degree(); ++i) {
39 auto childTreePath = Dune::TypeTree::push_back(treePath, i);
40 forEachLeafOrPowerLeafNode(tree.child(i), childTreePath, powerFunc, leafFunc);
41 }
42 }
43 } else {
44 auto indices = std::make_index_sequence<Tree::degree()>{};
45 Dune::Hybrid::forEach(indices, [&](auto i) {
46 auto childTreePath = Dune::TypeTree::push_back(treePath, i);
47 forEachLeafOrPowerLeafNode(tree.child(i), childTreePath, powerFunc, leafFunc);
48 });
49 }
50}
51} // namespace Ikarus::utils
Definition: algorithms.hh:17
void forEachLeafOrPowerLeafNode(T &&tree, TreePath &&treePath, PowerFunc &&powerFunc, LeafFunc &&leafFunc)
A function which loops over all the nodes of a tree and performs different actions for a power node (...
Definition: traversal.hh:30