Commit 2db5ac9d authored by Simon Praetorius's avatar Simon Praetorius

Merge branch 'issue/deprecate_foreach_node' into 'master'

Deprecate forEachNode with multiple callbacks

See merge request !88
parents e942adac d4c5284b
Pipeline #33973 passed with stage
in 2 minutes
......@@ -4,6 +4,8 @@ Changes
TypeTree 2.8-git
----------------
- The `forEachNode()` traversal function with multiple callbacks is deprecated. Use the
more general `applyToTree()` instead.
- Removed the type aliases for the storage type `Storage` and `ConstStorage` in the
node implementations.
- The memberfunction `childStorage()` in the nodes now consistently take an index or an
......
......@@ -231,9 +231,11 @@ namespace Dune {
* \param preFunc This function is called for each inner node before visiting its children
* \param leafFunc This function is called for each leaf node
* \param postFunc This function is called for each inner node after visiting its children
*
* \deprecated Use the more general \ref applyToTree instead.
*/
template<class Tree, class PreFunc, class LeafFunc, class PostFunc>
void forEachNode(Tree&& tree, PreFunc&& preFunc, LeafFunc&& leafFunc, PostFunc&& postFunc)
[[deprecated]] void forEachNode(Tree&& tree, PreFunc&& preFunc, LeafFunc&& leafFunc, PostFunc&& postFunc)
{
Detail::forEachNode(tree, hybridTreePath(), preFunc, leafFunc, postFunc);
}
......@@ -247,9 +249,11 @@ namespace Dune {
* \param tree The tree to traverse
* \param innerFunc This function is called for each inner node before visiting its children
* \param leafFunc This function is called for each leaf node
*
* \deprecated Use the more general \ref applyToTree instead.
*/
template<class Tree, class InnerFunc, class LeafFunc>
void forEachNode(Tree&& tree, InnerFunc&& innerFunc, LeafFunc&& leafFunc)
[[deprecated]] void forEachNode(Tree&& tree, InnerFunc&& innerFunc, LeafFunc&& leafFunc)
{
Detail::forEachNode(tree, hybridTreePath(), innerFunc, leafFunc, NoOp{});
}
......
......@@ -126,9 +126,31 @@ auto powerNode(P&& p, C0&& c0, C&&... c)
}
template<class PreOp = Dune::TypeTree::NoOp, class PostOp = Dune::TypeTree::NoOp, class LeafOp = Dune::TypeTree::NoOp>
struct GenericVisitor
: Dune::TypeTree::TreeVisitor
, Dune::TypeTree::DynamicTraversal
{
GenericVisitor(PreOp const& preOp = {}, LeafOp const& leafOp = {}, PostOp const& postOp = {})
: preOp_(preOp)
, leafOp_(leafOp)
, postOp_(postOp)
{}
template<class Node, class TreePath>
void pre(Node&& node, TreePath tp) const { preOp_(node, tp); }
template<class Node, class TreePath>
void leaf(Node&& node, TreePath tp) const { leafOp_(node, tp); }
template<class Node, class TreePath>
void post(Node&& node, TreePath tp) const { postOp_(node, tp); }
private:
PreOp preOp_;
LeafOp leafOp_;
PostOp postOp_;
};
int main()
......@@ -159,11 +181,12 @@ int main()
{
std::size_t inner = 0;
std::size_t leaf = 0;
forEachNode(tree, [&](auto&& node, auto&& path) {
applyToTree(tree, GenericVisitor{
[&](auto&& node, auto&& path) {
++inner;
}, [&](auto&& node, auto&& path) {
++leaf;
});
}});
test.check(inner==2)
<< "Counting inner nodes with forEachNode failed. Result is " << inner << " but should be " << 2;
test.check(leaf==4)
......@@ -183,7 +206,7 @@ int main()
auto countVisit = [] (auto&& node, auto&& path) {
++(node.value());
};
forEachNode(tree, countVisit, countVisit, countVisit);
applyToTree(tree, GenericVisitor{countVisit, countVisit, countVisit});
std::size_t visits=0;
forEachNode(tree, [&](auto&& node, auto&& path) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment