forEachNode interface for tree-traversal with flexibla treePathType
In Merge-Request !2 (merged) a nice interface for tree-traversal is proposed. This fixes the treepath and traversal type to dynamic
.
Is it somehow possible to extend the interface, so that one can choose the traversal type, i.e. DynamicTraversal
or StaticTraversal
(or maybe HybridTraversal
, see #3 (closed)). Maybe something like
template <class Tree, class PreFunc, class LeafFunc, class PostFunc,
class Traversal = DynamicTraversal, TreePathType::Type treePathType = Traversal::treePathType>
void forEachNode(Tree&& tree, PreFunc&& preFunc, LeafFunc&& leafFunc, PostFunc&& postFunc,
Traversal = {})
{
ApplyToTree(tree, Impl::callbackVisitor(preFunc, leafFunc, postFunc, treePathType{}));
}
This includes the check, that the last element provides a static treePathType
member. The class CallbackVisitor may be parametrized with the treePathType
, i.e.
template <class PreFunc, class LeafFunc, class PostFunc, TreePathType::Type tpt>
class CallbackVisitor
: public TreeVisitor
{
public:
TreePathType::Type treePathType = tpt;
/*...*/
};
What about the specialization for inner + leaf or only leaf? Either, the SFINAE check as above for the last argument works, or one could make the treePathType
container argument more explicit, i.e.
namespace TreePathType {
enum Type { fullyStatic, mostlyStatic, dynamic };
}
template <TreePathType::Type tpt>
struct TreePathType_t { using treePathType = tpt; };
using StaticTraversal = TreePathType<TreePathType::fullyStatic>;
using DynamicTraversal = TreePathType<TreePathType::dynamic>;
using HybridTraversal = TreePathType<TreePathType::mostlyStatic>;
and then using a more concrete function parameter for forEachNode
without SFINAE:
template <class Tree, class NodeFunc, TreePathType::Type tpt = TreePathType::dynamic>
void forEachNode(Tree&& tree, NodeFunc&& nodeFunc, TreePathType<tpt> = {})
{ ... }