Skip to content

WIP: Feature/simple treetransformation

Carsten Gräser requested to merge feature/simple-treetransformation into master

This demonstrates how to implement tree transformation manually with the help of some small utilities. For example the transformation in can be written as

struct GenericBasedTransformation
  auto operator()(const SimpleLeaf& node) {
    return TargetLeaf(node, *this);

  template<class Node,
    std::enable_if_t<hasImplementationTag<Node, SimplePowerTag>(), int> = 0>
  auto operator()(const Node& node) {
    return Dune::TypeTree::genericPowerNodeTransformation<TargetPower>(node, *this);

  template<class Node,
    std::enable_if_t<hasImplementationTag<Node, SimpleCompositeTag>(), int> = 0>
  auto operator()(const Node& node) {
    return Dune::TypeTree::genericCompositeNodeTransformation<TargetComposite>(node, *this);

This will do the same as the current mechanism together with the declaration

struct TestTransformation {};

// register leaf node
template<typename SL>
registerNodeTransformation(SL* sl, TestTransformation* t, SimpleLeafTag* tag);

template<typename SP>
registerNodeTransformation(SP* sp, TestTransformation* t, SimplePowerTag* tag);

template<typename SC>
registerNodeTransformation(SC* sc, TestTransformation* t, SimpleCompositeTag* tag);

Notice that it's comparably short but has certain advantages:

  • More readable, easier to understand because you directly see what's happening. That's not quite the case for the declarative style to define transformations.
  • Easily customizable. Since you write the transformation directly instead of a declaration hooking into some abstract mechanism, you can easily adjust parts of the code to your needs. E.g. instead of hard-wiring the customization by tags into the interface you can switch overloads using whatever condition you want.
  • Don't clutter the namespace by 'registering' transformation declarations.

Have a look at for the example. Notice that this does nor propose an interface change but more a different convention.

This relies on core/dune-common!495 (merged).

Merge request reports