|
Boost Users : |
From: David Abrahams (dave_at_[hidden])
Date: 2005-04-27 05:28:25
Joe McCay <joemccay_at_[hidden]> writes:
> David Abrahams <dave_at_[hidden]> writes:
>> Are you asking about runtime lambda expressions as in the Boost Lambda
>> library, or compile-time lambda expressions as in MPL?
>>
>> --
>> Dave Abrahams
>> Boost Consulting
>> www.boost-consulting.com
>
> I was talking about MPL because that is the only one I have studied
> at the moment. What is the difference between the two outside of the
> obvious runtime/compile-time difference?
Well, the syntax. MPL's compile-time lambdas never use parens as in
the _1(5) you cited.
> I was trying to figure out how a particular placeholder gets its
> arguments to choose from when deciding the argument (argument 1 for
> _1 etc.).
It's just in the definition of the placeholders
template <int> struct arg;
typedef arg<1> _1;
typedef arg<2> _2;
…
template <> struct arg<N>
{
template <
class A1 = void_
, class A2 = void_
…
, class AM = void_
>
struct apply
{
typedef AN type;
};
};
and the way arguments are passed through from apply_wrap.
apply_wrap<_2, int, int*, int**, int***>::type => int*
Maybe this simplified definition of lambda would help:
template <class T>
struct lambda { typedef T type; };
template < template <class> class F, class A1 >
struct lambda< F<A1> >
: if_<
is_placeholder_expression< F<A1> >
, bind< quote1<F>, typename lambda<A1>::type >
, F<A1>
>
{};
template < template <class,class> class F, class A1, class A2 >
struct lambda< F<A1,A2> >
: if_<
is_placeholder_expression< F<A1,A2> >
, bind<
quote2<F>
, typename lambda<A1>::type, typename lambda<A2>::type
>
, F<A1,A2>
>
{};
//...
-- Dave Abrahams Boost Consulting www.boost-consulting.com
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