Hacker News new | past | comments | ask | show | jobs | submit login
Self-inlining anonymous closures in C++ (might.net)
52 points by adg001 on Sept 23, 2010 | hide | past | favorite | 8 comments



Sorry, I can't see how this is an improvement over Boost::Phoenix:

http://www.boost.org/doc/libs/1_44_0/libs/spirit/phoenix/doc...


It isn't meant to be an improvement or a replacement.

It's just a tutorial on how such things are done. :)


Thanks for the pointer!


Now you get to run yourself in Valgrind to see if your guess about who's supposed to free it is correct.


A lot of people will read this and think "damn C++ is such an ugly language, it should never allow the programmer to do this!".

The reality is that that kind of technique allows to produce extremely fast code because the compiler has got so much "certain" information at compile time that it can optimize very aggressively.

It's more powerful than vanilla C macros because it works with the compiler, not the pre-processor.


C++ is the highest-level language that I can accurately guess the assembly that will be actually run by the processor.

YMMV whether that's a blessing or a curse, though!


$ in C++ identifiers is a nonstandard extension that gcc allows on some platforms - cool (and not portable).


You could use, say, "ARG_" instead and it would work just the same. (Phoenix uses "arg".)




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: