Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2004-12-27 20:19:30


David Greene wrote:
> All right, I'm still trying to figure out the MPL lambda stuff.
>
> I had expected this to work:
>
> template<typename Arg>
> some func {
> typedef ... type;
> };
>
> typedef transform<
> sequence,
> some_func<_>
> >::type result;
>
> But I get a compiler error about a missing apply<> in some_func.

Because some_func isn't defined anywhere?
What compiler, BTW?

> This works:
>
> typedef transform<
> sequence,
> quote1<some_func>
> >::type result;
>
> I don't understand why the placeholder doesn't convert some_func
> to an appropriate metafunction class.

I don't understand why/how you could expect it to. It's not as though
the MPL can retroactively generate a specialization of some_func that
has a nested ::apply<> metafunction.

Assuming you meant to write some_func at the top and not func,
some_func<_> is a placeholder expression and therefore a lambda
expression. Unless your compiler is broken, that should be sufficient
to allow it to be passed as the 2nd argument to transform.

> Similarly, I tried to use unpack args:
>
> template<typename Arg1, typename Arg2>
> some_func2 {
> typedef ... type;
> };
>
> typedef transform<
> zipped_sequence,
> unpack_args<some_func2<_,_>
> >::type result;
>
> The compiler complained about a missing apply<> in some_func2.

Looks like it should have been a syntax error. Your <>s don't nest.

> Again, this worked:
>
> typedef transform<
> zipped_sequence,
> unpack_args<quote2<some_func2> >
> >::type result;
>
> Is it because I'm using _ rather than _1 and _2?

Shouldn't be. Examples from
http://www.boost-consulting.com/metaprogramming-book that use _ in that
way work just fine, and were tested with at least 2 compilers.

> The examples
> in the MPL manual using is_same, etc. work fine for me.

I suggest you post the precise examples that are failing for you rather
than summaries, and tell us what compiler you're testing on.

-- 
Dave Abrahams
Boost Consulting
http://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