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-06 11:58:42


On 1/6/2011 11:39 AM, Hossein Haeri wrote:
> Dear Eric,
>
> I will certainly have another read over make_expr. But, I have a
> feeling that I might not have explained what I need very well. So,
> with some connection to the function streaming thing we were in
> contact on previous threads, here is an example:
>
> MyClass mc(_1 >> &f >> &g >> &h);
> mc.set_input(-61.1);
> cout << mc.value();//returns h(g(f(-61.1)))
>
> Now, are you telling me that I can store that "_1 >> &f >> &g >> &h"
> bit in a data member of mc using make_expr? If so, what will the type
> of that data member be? Or, are you suggesting a totally different
> design?

Ah. That part (the usage) wasn't clear. No, you can't use it like that.
I would suggest transforming the expression into a unary function object
(see my article on cpp-next.com about function composition), and be sure
your transform also stores everything by value. (Or pass everythying
through deep_copy.) Then store the resulting unary function in a
boost::function, so it's type-erased.

HTH,

-- 
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