________________________________
De: Dave Abrahams
On Sat, Apr 14, 2012 at 5:41 PM, Mathias Gaunard
wrote: On 14/04/12 17:00, Kevin Wu Won wrote:
This is C++11 only because it's quite pointless without lambda functions. I've tested it with gcc 4.7. It doesn't work on gcc 4.6, which can't handle the variadic templates.
It can be done in C++03 and expression-template-based lambdas just fine as well.
All you need to do is generate a function object that inherits recursively from a set of other function objects.
The function objects in question need to be either monomorphic or to be sufficiently constrained with SFINAE so that each operator() overload is not ambiguous.
Unfortunately, Boost.Phoenix was never extended to support this.
I really like the idea, and i think the C++11-based solution above is nice! I didn't have the time yet to glance through the code though ...
Phoenix didn't tackle that yet because it is a hard problem ... the main problem is the syntax how to express which lambda is responsible for what types. The above solution with C++11 lambdas is nice indeed!
Yeah, the first time I've actually been happy that non-polymorphic lambdas exist! Nice idea, Kevin!
However, what's missing is something like a "catch all" aka a templated lambda ...
...ah, yes... there's the rub. And my day is now spoiled :-) There is a catch all case. Just provide a lambda for boost::blank. See the original thread on StackOverflow where Me and R. Martinho Fernandes came up with the template syntax. There is also a complete code snippet with test cases on the post http://stackoverflow.com/q/7867555/170521 Charles J. Quarra