Hi Arthur,
What you suggested is one of the workarounds I described in the original posting - it works for Motivating Example 1 but not for Motivating Example 2.
You gave only one-half of a motivating example. I fleshed it out into a whole one. I asked you to show the code relating to the vague "AST" idea, but you haven't done so yet.
The problems are:
* If you wish to re-use the visitor, you need a mechanism to update the captured reference, and you must remember to update it every time you call the visitor, and there can be many call sites.
In the code I showed, the visitor is stateless; it has no captures.
* If the variant is an rvalue, you end up holding two references (of different types) to the same object, so you either forfeit rvalue-ness or break the unique ownership semantics.
Can you show an example?
–Arthur