|
Boost Users : |
Subject: Re: [Boost-users] nest mpl::lambda
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2013-02-24 00:09:23
On Sat, Feb 23, 2013 at 3:56 PM, Jeffrey Lee Hellrung, Jr. <
jeffrey.hellrung_at_[hidden]> wrote:
> On Sat, Feb 23, 2013 at 2:32 AM, Niitsuma Hirotaka <
> hirotaka.niitsuma_at_[hidden]> wrote:
>
>> I would like to use mpl::lambda in nest.
>>
>> In this case works fine.
>> ---------
>> typedef
>> boost::mpl::lambda<boost::mpl::max<boost::mpl::_1,boost::mpl::_2>
>> > my_max;
>> typedef boost::mpl::fold<
>> boost::mpl::vector_c<int,1,7,0,-2,5,-1>
>> , boost::mpl::int_<6>
>> //, boost::mpl::max<boost::mpl::_1,boost::mpl::_2>
>> , my_max
>> >::type r2;
>>
>> BOOST_MPL_ASSERT(( boost::is_same< r2, boost::mpl::integral_c<int, 7> >
>> ));
>> ---------
>>
>> However
>>
>> ---------
>>
>>
>> typedef boost::mpl::lambda<
>> boost::mpl::fold<
>> boost::mpl::_1
>> ,boost::mpl::front<boost::mpl::_1>
>> ,my_max
>> >::type >::type my_max_types;
>>
>
Also: remove the ::type from the fold<> expression. Works for me after that
(and the fix with adding the ::type on the definition of my_max). I would
think you would've gotten a compiler error at this point but, meh.
typedef my_max_types::apply<boost::mpl::vector_c<int,1,7,0,-2,5,-1>
>> >::type r3;
>>
>>
>> BOOST_MPL_ASSERT(( boost::is_same< r3, boost::mpl::integral_c<int, 7> >
>> ));
>> ///error => becomes boost::mpl::integral_c<int, 1>
>> ---------
>>
>>
>> How to define such nest lambda in mpl?
>>
>
> Uh, I see a red flag in that you don't grab the nested type typedef from
> your mpl::lambda invocations, i.e., I think you should have
>
> typedef mpl::lambda< mpl::max< mpl::_1, mpl::_2 > >::type my_max;
>
> Incidentally, you could also do
>
> typedef mpl::quote2< mpl::max > my_max
>
> (Well, assuming mpl::max doesn't have some hidden default parameters...)
>
> Without grabbing the type typedef in your mpl::lambda invocation, your use
> of mpl::_1 and mpl::_2 are "exposed" to premature substitution.
>
> - Jeff
>
>
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