Hi
I work with a nested tree-like data structure template (that happens
to be a tuple of vectors of tuples of trees of something, with
different tuple elements having different types)
I need to define a variety of ELEMENTWISE operations, like
a. increment all leaves (unary)
b. match two data structures (binary)
c. subtract two operands, write into third (ternary)
d. increment the first operand by a product of second, third and
fourth (quaternary)
... etc.
Because of the complexity of the data structure (it's more than a
simple tree), recursing through the whole thing requires 50 lines of
code.
I'd like to avoid writing this boilerplate code for each operation,
obviously.
If all elements in a given structure had the same type, I could define
iterators for this data structure, which would ease the task.
If all of the operations to be defined were unary, a visitor pattern
of some sort would be useful here (although even then, I would need a
const and non-const versions).
However, neither of these conditions applies. I could implement a
visitor-like pattern for each arity (up to 4), but that's roughly 300
lines of very dull code, ignoring const-ness.
Considering that a quaternary procedure can have 2^4 = 16 const-ness
types, this makes the problem of factoring out the boilerplate
recursion code for any possible elementwise operation even harder
(thousands of lines of code) and pointless.
Any suggestions?