c++ - Boost MPL nested lambdas -


i have been trying grips boost mpl.

as simple exercises, tried:

typedef vector_c<int, 1, 2, 3, 4, 5>::type example_list;  typedef transform<example_list, times<_, int_<2> > >::type doubled_example_list;  typedef transform<example_list, negate<_> >::type negated_example_list;  boost_static_assert((at_c<negated_example_list, 2>::type::value==-3)); boost_static_assert((at_c<doubled_example_list, 4>::type::value==10)); 

these work fine. however, following attempt not compile:

typedef transform<_, negate<_> > negate_a_list;  typedef apply<negate_a_list, example_list>::type negated_example_list_2;  boost_static_assert((at_c<negated_example_list_2, 2>::type::value==-3)); 

i think scope of placeholders in negate_a_list, not sure how fix it. ideas? suspect of assumptions syntax , semantics of mpl flawed. grateful tips grokking mpl.

p.s. here preamble above code:

#include <boost/mpl/vector_c.hpp> #include <boost/mpl/transform.hpp> #include <boost/static_assert.hpp> #include <boost/mpl/placeholders.hpp> #include <boost/mpl/times.hpp> #include <boost/mpl/size_t.hpp> #include <boost/mpl/apply.hpp> #include <boost/mpl/lambda.hpp> #include <boost/mpl/negate.hpp> #include <boost/mpl/at.hpp>  using namespace boost::mpl; using namespace boost::mpl::placeholders; 

thanks luc touraille's comment on question, boost mailing list provides the answer. code works:

typedef transform<_, lambda<negate<_> >::type > negate_a_list;  typedef apply<negate_a_list, example_list>::type negated_example_list_2;  boost_static_assert((at_c<negated_example_list_2, 2>::type::value==-3)); 

note addition of lambda<...>::type wrapping around lambda expression. sufficient bound scope of placeholder.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -