Subject: Re: [Boost-users] [lamda] smart self binding of a function object
From: Geoff Hilton (geoff.hilton_at_[hidden])
Date: 2010-05-12 11:01:43


On 11/05/2010 7:47 PM, alfC wrote:
>>> You'll have to make operator() a template:
>
>>> template<class T>
>>> function<double(double)> operator()(const T& x_arg, double y_arg);
>
>>> What if I want to restrict T to lambda expressions?
>>
>> What about forcing T to be or be derived from an expression template
>> base class?
>
> How can I do that? Can you point me to the right documentation if
> any.
>
> In the context of Boost.Lambda there is no common base class for all
> expression templates (is there?), for example the placeholders do not
> inherit from anything. The only thing I found was the subclass 'sig'
> that seems to be defined for all expression types. But I am still
> scratching my head on how to expoit this 'sig' subclass.
>
> Now that I think one obvious way to restrict T is to be an expression
> template that 'returns' a double (or convertible to 'double'), this
> information is contained in the sig subclass. But I am confused now to
> do any progress.
>
> Alfredo

http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Expression-template

http://www.boost.org/libs/numeric/ublas/doc/expression_concept.htm

C++ Expression Templates
By Angelika Langer and Klaus Kreft, March 01, 2003
http://www.drdobbs.com/184401627

I have yet to tinker with expression templates in any meaningful way
(aside from copy/pasting the example from wikibooks.org and playing with
it), so beyond giving you those links as guides there's not much I can
do. I do know that it's exactly what you want though and that the keys
to your kingdom are the Var and Constant classes (or equivalent) from
the wikibooks.org article.

Good luck!
Geoff