
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