[phoenix] A simple lambda func as boost::function

Hi boost gurus, after some time and a lot of pain I somehow managed to work with boost.lambda in a way that actually outweighs the costs (code elegance versus time spent compiling it), but I miss some features (like local variables) I see in that cute phoenix documentation and a lot of mailing list threads which all seem to propose using phoenix rather than lambda (and it indeed looks a lot better). But whenever I try to use it, I somehow fail at the most simple tasks. Take for example this minimalistic code example here (note the use of #define USE_LAMBDA): http://pastebin.com/m3f590a01 Both versions (with and without USE_LAMBDA defined) compile well on the most recent stable g++ compiler, but the phoenix version does not output anything. Not at all. Also note, that this exact lambda expression is mentioned here: http://tinyurl.com/ybmp2lw (well, without the << "\n" but that doesn't change the problem) Could someone please enlighten me by telling me what I have to do here? I should mention I am bound to boost::function, not some funky phoenix::actor derivations... Greets, Richard Vock

Richard Vock wrote:
Hi boost gurus,
after some time and a lot of pain I somehow managed to work with boost.lambda in a way that actually outweighs the costs (code elegance versus time spent compiling it), but I miss some features (like local variables) I see in that cute phoenix documentation and a lot of mailing list threads which all seem to propose using phoenix rather than lambda (and it indeed looks a lot better).
But whenever I try to use it, I somehow fail at the most simple tasks. Take for example this minimalistic code example here (note the use of #define USE_LAMBDA): http://pastebin.com/m3f590a01
Both versions (with and without USE_LAMBDA defined) compile well on the most recent stable g++ compiler, but the phoenix version does not output anything. Not at all. Also note, that this exact lambda expression is mentioned here: http://tinyurl.com/ybmp2lw (well, without the << "\n" but that doesn't change the problem)
Could someone please enlighten me by telling me what I have to do here? I should mention I am bound to boost::function, not some funky phoenix::actor derivations...
Try removing lambda: doSth(cout << arg1 << "\n"); Also, endl works on phoenix: doSth(cout << arg1 << std::endl); Regards, -- Joel de Guzman http://www.boostpro.com http://spirit.sf.net http://www.facebook.com/djowel Meet me at BoostCon http://www.boostcon.com/home http://www.facebook.com/boostcon

Hehe, I already tried that and it gives me this handy little error message: http://pastebin.com/m787325af Essentially telling me something I don't understand at all about boost::phoenix::at not being a function...
Richard Vock wrote:
Hi boost gurus,
after some time and a lot of pain I somehow managed to work with boost.lambda in a way that actually outweighs the costs (code elegance versus time spent compiling it), but I miss some features (like local variables) I see in that cute phoenix documentation and a lot of mailing list threads which all seem to propose using phoenix rather than lambda (and it indeed looks a lot better).
But whenever I try to use it, I somehow fail at the most simple tasks. Take for example this minimalistic code example here (note the use of #define USE_LAMBDA): http://pastebin.com/m3f590a01
Both versions (with and without USE_LAMBDA defined) compile well on the most recent stable g++ compiler, but the phoenix version does not output anything. Not at all. Also note, that this exact lambda expression is mentioned here: http://tinyurl.com/ybmp2lw (well, without the << "\n" but that doesn't change the problem)
Could someone please enlighten me by telling me what I have to do here? I should mention I am bound to boost::function, not some funky phoenix::actor derivations...
Try removing lambda:
doSth(cout << arg1 << "\n");
Also, endl works on phoenix:
doSth(cout << arg1 << std::endl);
Regards,

Richard Vock wrote:
Hehe, I already tried that and it gives me this handy little error message: http://pastebin.com/m787325af
Essentially telling me something I don't understand at all about boost::phoenix::at not being a function...
Please don't top post.
Richard Vock wrote:
Hi boost gurus,
after some time and a lot of pain I somehow managed to work with boost.lambda in a way that actually outweighs the costs (code elegance versus time spent compiling it), but I miss some features (like local variables) I see in that cute phoenix documentation and a lot of mailing list threads which all seem to propose using phoenix rather than lambda (and it indeed looks a lot better).
But whenever I try to use it, I somehow fail at the most simple tasks. Take for example this minimalistic code example here (note the use of #define USE_LAMBDA): http://pastebin.com/m3f590a01
Both versions (with and without USE_LAMBDA defined)
compile
well on the most recent stable g++ compiler, but the phoenix version does not output anything. Not at all. Also note, that this exact lambda expression is mentioned here: http://tinyurl.com/ybmp2lw (well, without the << "\n" but that doesn't change the problem)
Could someone please enlighten me by telling me what I
This works for me and I think it is what you are after.
Am I missing something? (btw ... notice that the int in
the function sig is by value ... not reference)
--------------------------------
#include <iostream>
#include

Please don't top post.
Yepp - already found out and hated me for that (if there would be any edit buttons..), so - sorry for that.
This works for me and I think it is what you are after. Am I missing something? (btw ... notice that the int in the function sig is by value ... not reference)
--------------------------------
#include <iostream> #include
#include void my_func( boost::function< void(int) > func ) { for( int i=0; i<5; ++i ) { func( i ); } }
int main() { using boost::phoenix::arg_names::arg1;
my_func( (std::cout << arg1 << '\n') );
return 0; }
This is very interesting, since exactly this code won't compile with my setup (error message looks very close to the one I supplied in my second post): g++ (GCC) 4.4.2 BOOST_VERSION 103900 BOOST_PHOENIX_VERSION 0x2000 // 2.0.0

Richard Vock wrote:
This works for me and I think it is what you are after. Am I missing something? (btw ... notice that the int in the function sig is by value ... not reference)
--------------------------------
#include <iostream> #include
#include void my_func( boost::function< void(int) > func ) { for( int i=0; i<5; ++i ) { func( i ); } }
int main() { using boost::phoenix::arg_names::arg1;
my_func( (std::cout << arg1 << '\n') );
return 0; }
This is very interesting, since exactly this code won't compile with my setup (error message looks very close to the one I supplied in my second post): g++ (GCC) 4.4.2 BOOST_VERSION 103900 BOOST_PHOENIX_VERSION 0x2000 // 2.0.0
I've now tried it with the following two combos: OS Compiler Boost Version Phoenix Version windows vc8 1_41_0 0x2000 linux g++_4.3.2 1_39_0 0x2000 Works fine for me. I only have gcc_4.3.2 on the virtual machine I was using. I'll reboot into linux later and check 4.4.2... but meanwhile, can you paste the error that you get with your setup and the source above? michael -- ---------------------------------- Michael Caisse Object Modeling Designs www.objectmodelingdesigns.com

Michael Caisse wrote:
Richard Vock wrote:
This works for me and I think it is what you are after. Am I missing something? (btw ... notice that the int in the function sig is by value ... not reference)
--------------------------------
#include <iostream> #include
#include void my_func( boost::function< void(int) > func ) { for( int i=0; i<5; ++i ) { func( i ); } }
int main() { using boost::phoenix::arg_names::arg1;
my_func( (std::cout << arg1 << '\n') );
return 0; }
This is very interesting, since exactly this code won't compile with my setup (error message looks very close to the one I supplied in my second post): g++ (GCC) 4.4.2 BOOST_VERSION 103900 BOOST_PHOENIX_VERSION 0x2000 // 2.0.0
I've now tried it with the following two combos:
OS Compiler Boost Version Phoenix Version windows vc8 1_41_0 0x2000 linux g++_4.3.2 1_39_0 0x2000
Works fine for me. I only have gcc_4.3.2 on the virtual machine I was using. I'll reboot into linux later and check 4.4.2... but meanwhile, can you paste the error that you get with your setup and the source above?
I don't think you need the extra parens. Regards, -- Joel de Guzman http://www.boostpro.com http://spirit.sf.net http://www.facebook.com/djowel Meet me at BoostCon http://www.boostcon.com/home http://www.facebook.com/boostcon

I've now tried it with the following two combos:
OS Compiler Boost Version Phoenix Version windows vc8 1_41_0 0x2000 linux g++_4.3.2 1_39_0 0x2000
Works fine for me. I only have gcc_4.3.2 on the virtual machine I was using. I'll reboot into linux later and check 4.4.2... but meanwhile, can you paste the error that you get with your setup and the source above?
Here's a paste of the lengthy error message: http://pastebin.com/me9890ad Done with the setup from my previous post. I tried upgrading to 1.41 (its now in the arch repos) and *it does compile and work* without changing any code. This looks as if the code from the previous version has been corrupted but I never changed it myself, so maybe I just stumbled upon a problem in the arch repos... I myself am confident with a working 1.41, so as far as my part in this ugly story goes: I'm fine and thank you for your patience (I should have tried upgrading before posting here but most of time *I* am the one who is wrong, not the library source)!

Richard Vock wrote:
This is very interesting, since exactly this code won't compile with my setup (error message looks very close to the one I supplied in my second post): g++ (GCC) 4.4.2 BOOST_VERSION 103900 BOOST_PHOENIX_VERSION 0x2000 // 2.0.0
As a datapoint builds without warnings and runs for me: gcc (Ubuntu 4.4.1-4ubuntu8) 4.4.1 BOOST_VERSION 0x19708 BOOST_PHOENIX_VERSION 0x2000 Patrick

Richard Vock wrote:
Hehe, I already tried that and it gives me this handy little error message: http://pastebin.com/m787325af
Essentially telling me something I don't understand at all about boost::phoenix::at not being a function...
Works for me on both VC9 and g++. Prints: 0 1 2 3 4 Header confusion perhaps? Regards, -- Joel de Guzman http://www.boostpro.com http://spirit.sf.net http://www.facebook.com/djowel Meet me at BoostCon http://www.boostcon.com/home http://www.facebook.com/boostcon
participants (4)
-
Joel de Guzman
-
Michael Caisse
-
Patrick Horgan
-
Richard Vock