I have a tree of objects, where each object has a std::vector
of pointers to its children. The class of the object has a rewrite()
method that is recursively applied to alter the object and its children, typically with the following transformations, where [N]
is the object being rewritten and (M)
is the element that rewrite()
returns:
(A) [A] / \ [A] / \ --> B X | --> (B) B C \ B C
What's the cleanest way of extending this setup to allow transformations like this?
A X | / \ [B] --> C A | | C (Y)
That is, those that re-root the tree, move an element, insert a new element, and return the inserted element. I'm having a hard time coming up with something nice that also involves minimal refactoring. Thoughts?