Boost logo

Boost :

From: Jaakko Jarvi (jajarvi_at_[hidden])
Date: 2004-03-10 14:20:14


On Mar 10, 2004, at 2:10 PM, Neal D. Becker wrote:

> I was just trying out lambda and I have a question.
>
> I have a template class Ave
> template<typename in_t, typename Scale>
> struct Ave {...}
>
> It takes a function type argument "Scale".
>
> Here's a test:
>
> typedef typeof (_1 * 0.1) some_type;
> some_type func (_1 * 0.1);
>
> // Ave<double, typeof (_1 * 0.1)> ave (_1 * 0.1); << this will work
> Ave<double, some_type> ave (func); << this will also
>
>
> What is the preferred way to do this without "typeof"? How do I get
> the
> type
> returned by the lambda expression to feed to the template Ave?
>

There is no direct way of getting to the type.
One can store a lambda expression into a boost::function, for which you
have to
specify the return and argument types:

boost::function<double (double)> func = _1 * 0.1;

   Cheers, Jaakko


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk