
I am just a beginner so my question could be very stupid. Please be patient. What is wrong with the following code? It should be clear enough what I am trying to do.
#include <iostream>
#include <boost/mpl/int.hpp> #include <boost/mpl/apply.hpp> #include <boost/mpl/plus.hpp> int main() { using namespace boost::mpl; // ... typedef apply< plus< _, int_<10> >, int_<1> >::type t; std::cout << typeid(t).name() << std::endl; typedef apply< plus< _, int_<10> >, _ > t2; typedef apply< t2, int_<1> >::type res; // ??? std::cout << typeid(res).name() << std::endl; } <<< Kiuhnm -- View this message in context: http://www.nabble.com/mpl%2C-apply%2C-placeholders-t1379886.html#a3705111 Sent from the Boost - Users forum at Nabble.com.

Kiuhnm wrote:
I am just a beginner so my question could be very stupid. Please be patient.
What is wrong with the following code? It should be clear enough what I am trying to do.
I'll start by saying that I didn't actually try out your code. That said, I think what you're seeing is the same issue I reported and explained in the link below, together with workaround. I never got an answer to that post, however... http://permalink.gmane.org/gmane.comp.lib.boost.devel/139253 The workaround is to use apply1 instead of apply in the placeholder expression. Try this, typedef apply1< plus< _, int_<10> >, _ > t2; Best regards, João

João Abecasis-2 wrote:
The workaround is to use apply1 instead of apply in the placeholder expression. Try this,
typedef apply1< plus< _, int_<10> >, _ > t2;
Thank you for your reply. Now the compiler reports far fewer errors (4). The main error should be caused by the following expression (but I'm not sure): integral_c<int,11>::apply< int_<1> > Kiuhnm -- View this message in context: http://www.nabble.com/mpl%2C-apply%2C-placeholders-t1379886.html#a3712192 Sent from the Boost - Users forum at Nabble.com.

I posted this question a few months ago, but I got pulled away to deal with more pressing work issues. So here it goes again: I'm trying to use lambda expressions to implement 'twice'. So I came up with typedef mpl::apply<_1, mpl::apply<_1, _2> > lambda_type; typedef lambda_type<boost::add_pointer<_1>, int> result_type; When I look at result_type, I get is_same<result_type, int*>::type::value evaluates to true. I expected that is_same<result_type, int**>::type::value would evaluate to true. Why is my lambda expression 'lambda_type' only returning it's second argument?? ------------------------------------------- Manson: My philosophy is: Don't think. I don't believe in the mind that you think with and scheme with. I don't believe in words. Reporter: If you don't believe in words, why do you use so many of them? Manson: Words are symbols. All I'm doing is jumbling the symbols in your brain. Everything is symbolic. Symbols are just connections in your brain. Even your body is a symbol. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com

Lucio Flores <dogboy_l@yahoo.com> writes:
I posted this question a few months ago, but I got pulled away to deal with more pressing work issues. So here it goes again:
I'm trying to use lambda expressions to implement 'twice'. So I came up with
typedef mpl::apply<_1, mpl::apply<_1, _2> > lambda_type;
typedef lambda_type<boost::add_pointer<_1>, int> result_type;
Surely that doesn't compile(?) lambda_type is a type; you can't follow it with a template argument list. -- Dave Abrahams Boost Consulting www.boost-consulting.com

--- David Abrahams <dave@boost-consulting.com> wrote:
Lucio Flores <dogboy_l@yahoo.com> writes:
I posted this question a few months ago, but I got pulled away to deal with more pressing work issues. So here it goes again:
I'm trying to use lambda expressions to implement 'twice'. So I came up with
typedef mpl::apply<_1, mpl::apply<_1, _2> > lambda_type;
typedef lambda_type<boost::add_pointer<_1>, int> result_type;
Surely that doesn't compile(?) lambda_type is a type; you can't follow it with a template argument list.
You're right! .... But it did compile.... So what's the correct usage? Would it be: typedef mpl::apply< lambda_type, boost::add_pointer<_1>, int>::type result_type; ??? ------------------------------------------- Manson: My philosophy is: Don't think. I don't believe in the mind that you think with and scheme with. I don't believe in words. Reporter: If you don't believe in words, why do you use so many of them? Manson: Words are symbols. All I'm doing is jumbling the symbols in your brain. Everything is symbolic. Symbols are just connections in your brain. Even your body is a symbol. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com

Lucio Flores <dogboy_l@yahoo.com> writes:
--- David Abrahams <dave@boost-consulting.com> wrote:
Lucio Flores <dogboy_l@yahoo.com> writes:
I posted this question a few months ago, but I got pulled away to deal with more pressing work issues. So here it goes again:
I'm trying to use lambda expressions to implement 'twice'. So I came up with
typedef mpl::apply<_1, mpl::apply<_1, _2> > lambda_type;
typedef lambda_type<boost::add_pointer<_1>, int> result_type;
Surely that doesn't compile(?) lambda_type is a type; you can't follow it with a template argument list.
You're right! .... But it did compile....
What compiler ate that without complaint?
So what's the correct usage? Would it be:
typedef mpl::apply< lambda_type, boost::add_pointer<_1>, int>::type result_type;
Yes, that looks correct. -- Dave Abrahams Boost Consulting www.boost-consulting.com

--- David Abrahams <dave@boost-consulting.com> wrote:
Lucio Flores <dogboy_l@yahoo.com> writes:
--- David Abrahams <dave@boost-consulting.com> wrote:
Lucio Flores <dogboy_l@yahoo.com> writes:
I posted this question a few months ago, but I got pulled away to deal with more pressing work issues. So here it goes again:
I'm trying to use lambda expressions to implement 'twice'. So I came up with
typedef mpl::apply<_1, mpl::apply<_1, _2> > lambda_type;
typedef lambda_type<boost::add_pointer<_1>, int> result_type;
Surely that doesn't compile(?) lambda_type is a type; you can't follow it with a template argument list.
You're right! .... But it did compile....
What compiler ate that without complaint?
gcc version 3.3.5 20050117 (prerelease) (SUSE Linux 9.3) But the following wont compile: typedef mpl::apply<_1, mpl::apply<_1, _2> > lambda_type; typedef mpl::apply<lambda_type, boost::add_pointer<_1>, int>::type answer_type; prog_3_6.cpp:22: error: no class template named `apply' in `struct lambda_type' prog_3_6.cpp:22: error: syntax error before `;' token ------------------------------------------- Manson: My philosophy is: Don't think. I don't believe in the mind that you think with and scheme with. I don't believe in words. Reporter: If you don't believe in words, why do you use so many of them? Manson: Words are symbols. All I'm doing is jumbling the symbols in your brain. Everything is symbolic. Symbols are just connections in your brain. Even your body is a symbol. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
participants (4)
-
David Abrahams
-
João Abecasis
-
Kiuhnm
-
Lucio Flores