|
Boost Users : |
Subject: Re: [Boost-users] [Proto] Storing an Expression Template as a Data Member
From: Hossein Haeri (powerprogman_at_[hidden])
Date: 2011-01-06 11:39:28
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?
TIA,
--Hossein
--- On Thu, 6/1/11, Eric Niebler <eric_at_[hidden]> wrote:
> From: Eric Niebler <eric_at_[hidden]>
> Subject: Re: [Boost-users] [Proto] Storing an Expression Template as a Data Member
> To: boost-users_at_[hidden]
> Date: Thursday, 6 January, 2011, 16:10
> On 1/6/2011 8:58 AM, Hossein Haeri
> wrote:
> > Dear all,
> >
> > Is there any way I can have classes with data members
> of type (proto)
> > expression templates? Here is where I get stuck:
> >
> > template<typename T> class MyClass { ... T
> expression_; };
> >
> > What type should T be?
> >
> > If you're wondering why on earth I might need that,
> here is an
> > explanation: Instances of MyClass need to store the
> lazy calculation
> > they will be performing later on when enough
> initialisation data is
> > available. Each instance of MyClass has its own
> FORMULATION for the
> > lazy calculation in terms of the initialisation data.
> They need to be
> > fed with these formulations and I thought (proto)
> expression
> > templates will perhaps do the job. But, then, I don't
> know how to
> > store these formulations until it's time for them to
> perform...
>
> If you use proto::make_expr to build expressions explicitly
> (instead of
> using the operator overloads), you can have completel
> control over how
> sub-expressions are stored. (You'll need them to be stored
> by value if
> you're saving the ET in a variable; otherwise, they'll go
> out of scope.)
>
> And if you're using proto::make_expr, you can use
> proto::result_of::make_expr to compute the type of the
> resulting ET.
>
> Read the docs for make_expr carefully. That should solve
> your problem.
>
> HTH,
>
> --
> Eric Niebler
> BoostPro Computing
> http://www.boostpro.com
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
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