|
Boost : |
From: Atry (pop.atry_at_[hidden])
Date: 2007-06-26 09:31:02
I wrote a intial version, I have tested it on cygwin ported gcc 3.4.4 and
msvc 7.1, for more infomation, see README and tests in zip packet in vault.
http://boost-consulting.com/vault/index.php?direction=0&order=&directory=Generic%20Programming
On 6/25/07, Atry <pop.atry_at_[hidden]> wrote:
>
> Hi everybody, in some case I want to have an template parameter of functor
> like this:
>
> ////////////////////
> template<typename Functor>
> double add(double l, double r)
> {
> return Functor::invoke(l, r);
> }
>
>
> int main()
> {
> // simply invoke:
> BOOST_ASSERT( BOOST_STATIC_LAMBDA_FUNCTOR(_1 + _2 * _3)::invoke(1, 3, 5)
> == 1 + 3 * 5 );
>
> // as a template parameter.
> BOOST_ASSERT( add<BOOST_STATIC_LAMBDA_FUNCTOR(_1 + _2)>( 0.1, 0.2) ==
> 0.1 + 0.2 );
>
> // define as a type
> typedef BOOST_STATIC_LAMBDA_FUNCTOR(_1 << _2 << _3) left_shift_type;
>
> // print hello world, first parameter(cout) is reference.
> left_shift_type::invoke<ostream&>(cout, "hello world", &endl<char,
> char_traits<char> >);
> }
> /////////////////////////////////////
>
> The BOOST_STATIC_LAMBDA_FUNCTOR used an internal BOOST_TYPEOF, could parse
> a lambda expression to a static type, which has a template function "invoke"
> with any type parameter. I think that would be useful and I have done some
> work on it. Is there anyone interested in it?
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk