On 16/10/2012 07:24 a.m., Bart Janssens wrote:
On Sun, Oct 14, 2012 at 1:20 AM, Agustín K-ballo Bergé
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?
Re-reading your question after Eric's nudge, I think this is similar
to a question I asked a while ago. Eric proposed replacing the
standard deep copy with a transform like this:
struct DeepCopy :
boost::proto::when // exceptions for terminals that need to be
stored by value
boost::proto::when<DeepCopy, boost::proto::_byval(DeepCopy)> > >
This can then be called like DeepCopy()(your_expr). The when<>
template in here has some exceptions for terminals that I did want to
keep by value, so if you remove that all terminals should be stored by
reference in the copy. Concretely in the above example, const doubles
and ints are stored by value in the copy, all other types including
non-const doubles and ints are kept by reference. Hope this helps!
This is quite smart! If I can combine this with my domain's `as_child`
then it is exactly what I need, I haven't even considered the
possibility of using transforms there. Thank you for your help.
Agustín K-ballo Bergé.-
proto mailing list