Boost logo

Proto :

Subject: [proto] Transform result_of nightmare and preserving terminal identity
From: Agustín K-ballo Bergé (kaballo86_at_[hidden])
Date: 2012-10-13 19:20:38

Hi All,

I'm experimenting with Proto to build a DSEL that operates on geometric
vectors. I'm trying to write a transform that would take an assign
expression and unroll it component wise. For instance, I want to replace

     p = q + r;


     p[0] = q[0] + r[0],
     p[1] = q[1] + r[1],
     p[N] = q[N] + r[N],

So far I have been able to *mostly* make it work by making a transform
template unroll_vector_expr that recursively unrolls the expression for
each vector component, in conjunction with a distribute_subscript
transform (which I shamelessly took from Eric's article on C++Next).

I don't seem to understand whats the rationale for the 'parameters' used
with `boost::result_of` and `result_of::make_expr`. The documentation,
examples and internal code seem to mix `Expr`, `impl::expr` and
`impl::expr_param`. I'm not sure what should I be using and when so that
the `result_type` matches the actual result type. Currently I made it
work by trial an error, by examining the error messages and fixing the
`const` and `&` discrepancies (code for the transform attached).
However, as soon as I deep copy the expression the terminals are no
longer hold by reference and my code fails. Which incidentally brings me
to my second question...

When deep copying an expression the 'identity' of the terminals is lost,
as each reference to a terminal results in a new hold by value terminal.
Consequently, expressions with side effects (like assignment) no longer
evaluate correctly. Is it possible to customize the expression
'semantics' so that when a deep copy is made terminals are copied only
the first time they are seen, and subsequent uses refer to that first
copy? Or should I be taking a completely different approach, perhaps by
leaving operations with side effects outside of the grammar?

Thanks in advance for any help, and sorry if any of my questions is
trivial or erroneous.

Agustín K-ballo Bergé.-

Proto list run by eric at