What additional data structures should be organized in order to take the first derivative of an abstract source tree (for string math expression)? Let's say, we have a tree for the string expression, which was built using boost::spirit. I.e each node have appropriate BOOST_FUSION_ADAPT_STRUCT/BOOST_FUSION_ADAPT_TPL_STRUCT definition. So, how to store an additional produced data struct-s to each node of primary AST and how they should be constructed?
I think, that they should be constructed via std::reference_wrapper< T const & > or boost::optional< T const & > to the fields (of type T) of original struct-s with the same layout. And they should form the arrays/vectors/deques for each node of source tree (where index is equal to n-th derivative of corresponding node of source tree). Each tree traverse with "derivator-visitor" should push_backs the next expression to each array for each node. In order to establish the correspondence of source nodes to arrays of theirs derivatives we can make they tagged.