Boost logo

Boost Users :

From: Daniel Wallin (dalwan01_at_[hidden])
Date: 2004-03-10 05:56:46


Matt Calabrese wrote:
> <snip>
> I'm still new to metaprogramming and the mpl lambda facilities and I'm
> having some trouble creating a metafunction which produces my desired type.
> This is what I've come up with, though it doesn't work - I'm assuming
> because of my second use of mpl::_1 in the nested template parameter of
> mpl::front in mpl::push_front (which I'd like to have represent the current
> state of the mpl::fold).
>
> template< typename vector_t >
> struct get_alternatives
> {
> typename mpl::fold_backward< vector_t,
> mpl::vector< epsilon_parser >,
> typename mpl::push_front< mpl::_1,
>
> spirit::alternative< mpl::_2,
>
> typename mpl::front< mpl::_1 >::type > >::type >::type type;
> };

The problem is that you are evaluating the nested metafunction calls.
What you want here is lazy evaluation:

   template< typename vector_t >
   struct get_alternatives
   {
       typedef typename mpl::fold_backward<
           vector_t
         , mpl::vector< epsilon_parser >
         , mpl::push_front<
               mpl::_1
             , spirit::alternative<
                   mpl::_2
                 , mpl::front<mpl::_1>
>
>
>::type type;
   };

typename mpl::front<mpl::_1>::type will evaluate mpl::front<> on a
placeholder argument, which doesn't make any sense.

HTH,

-- 
Daniel Wallin

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