On Mon, Jan 23, 2012 at 6:03 PM, Linh Ha <lha@sci.utah.edu> wrote:
Dear all,

I try to learn Meta-programing but i got stuck with lambda meta-function and place holder.
I try to compile very simple program

#include <boost/bind.hpp>
#include <boost/mpl/lambda.hpp>
#include <boost/type_traits.hpp>

template <class F, class X>
struct twice : F::template apply<typename F::template apply<X>::type > {
};

template <class X>
struct two_pointers
: twice<typename boost::mpl::lambda<boost::add_pointer<_1> >::type, X>
{};
int main(int argc, char** argv) {
return 0;
}

It is from the boost tutorial http://www.boost.org/doc/libs/1_48_0/libs/mpl/doc/tutorial/the-lambda-metafunction.html . But it can not be complied. The error messages are

main.cpp:21: error: type/value mismatch at argument 1 in template parameter list for ‘template<class T> struct boost::add_pointer’
main.cpp:21: error: expected a type, got ‘<unnamed>::_1’
main.cpp:21: error: template argument 1 is invalid
main.cpp:21: error: template argument 3 is invalid
main.cpp:21: error: template argument 1 is invalid
main.cpp:22: error: expected ‘::’ before ‘{’ token
main.cpp:22: error: expected class-name before ‘{’ token

I use

g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5

I have no idea what happened. Any inside would be appreciated. It is important I think since lambda is used all over place with MPL.

Thanks,
Linh Ha


Just on a first glance, looks like you're mistaking ::_1 (placeholder from Boost.Bind) for boost::mpl::_1 (placeholder from Boost.MPL). They're incompatible; try using the latter...?

- Jeff