Boost logo

Boost Users :

Subject: Re: [Boost-users] [Proto] Storing an Expression Template as a Data Member
From: Eric Niebler (eric_at_[hidden])
Date: 2011-01-08 11:45:06


On 1/8/2011 9:06 AM, Hossein Haeri wrote:
> Hi Eric,
>
>>> Does the fact that I store formula_ by value (as in
>> line ***) shoot the trouble of dangling references?
>>
>> No, the problem still exists. You're storing the outer-most node by
>> value, but all the inner nodes (temporary objects constructed while
>> building the expression) are held by reference. At the very least, the
>> constructor of MyClass needs to pass the incoming expression through
>> deep_copy.
>
> So, what about the following?
>
> #define DEFINE_MY_CLASS(name, exp) \
> MyClass<result_of::deep_copy<BOOST_TYPEOF(exp)>::type> name(deep_copy(exp))

Sure. Or you could move the deep-copy action an implementation detail of
MyClass and keep the macro simple. Whichever.

>> That article takes a sequence of function calls and turns them into a
>> single callable object. You're taking a sequence of function calls and
>> are turning them into a callable object.
>
> I see. OK, so you're basically saying that the >> syntax can be avoided and that we can use simple function object composition instead with no need for Protofication.

No, I'm not saying that. I'm saying you can use >> and Proto to build an
expression tree, and use a transform to compose that tree into a
function object. But the principles of that transformation are the same
as what's described in the article.

Once you have the composed function as a function object, you can store
it in a boost::function.

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net