
Phil Endecott wrote:
Thomas Heller wrote:
I would be interested in what limitations you ran into using Boost.Lambda and if you are aware of the recent efforts that were put into Boost.Phoenix?
To my mind this example looks a lot clearer if you reformat it as follows:
BOOST_LOCAL_FUNCTION( (void) (add)( (double)(num) (const bind)((factor)) (bind)((&sum)) ) ) { sum += factor * num; std::clog<< "Summed: "<< sum<< std::endl; } BOOST_LOCAL_FUNCTION_END(add) add(100.0);
As far is a am concerned, I still find this syntax overly verbose. I do realize though that this is just a toy example. For better comparison, Here is how the same thing would like in Boost.Phoenix:
boost::function<void(double)> add =( ref(sum) += factor * _1, std::clog << var("Summed: ") << sum << std::endl ) ; add(100.0);
but how are the above examples (both of Boost.Local and Boost.Phoenix) not C++ syntax?
Well, to spell out the obvious, the way that the Boost.Local code terminates statements with ';' while the Pheonix code uses ',' is a reasonably good example of "normal" vs. "obfuscated" syntax. Then there is all the replacement of keywords, changing of brackets, numbered vs. named parameters, and extra bits of fluff like ref() and bind(). No doubt it seems like second-nature once you are used to it, but I'd much prefer to use "normal" C++ syntax to write lambdas if I can.
Point taken. OTOH the macros used to define the local functions are not even close to those of either C++0x lambdas or regular C++ functions. The "fluff" and "obfuscated" syntax you find in Phoenix et al in the body of the expressions, was shifted in Boost.Local to the function decelerator.
Again, since the future is no doubt C++0x lambdas, should we be trying to converge towards that? I.e. choosing whatever approach has the closest syntax to that?
1) It is, IMHO, not only a matter of the syntax used in the body of the statements (regular C++ with Boost.Local vs. stylized, emulated C++ in Boost.Phoenix). It is how the general usecase is, which is probably a inplace definition of some unnamed function, to be used in some std algorithm, as callback in for example boost.asio etc. Boost.Local unfortunately can not deliver that inplace definition: Boost.Local: BOOST_LOCAL_FUNCTION(...) {}BOOST_LOCAL_FUNCTION_END(...) std::for_each(v.begin(), v.end(), ...); C++0x lambdas, Boost.Bind, Boost.Lambda and Boost.Phoenix: std::for_each(v.begin(), v.end(), some_lambda_expression); 2) Even though C++0x will support unnamed functions as a language feature, Boost.Phoenix will not become obsolete. Quite the opposite, Boost.Phoenix offers a lot of advantages over C++0x lambdas. (Forgive me if I won't go into detail here about that, this thread is about Boost.Local) Whereas Boost.Local are just a complicated way to express what can be done with C++0x lambdas, I see no real advantage of Boost.Local over C++0x lambdas. Regards, Thomas