Elegant porting of lambda expressions in C++
Since lambda expressions require GCC version > 4.4: what is the most elegant or fastest (yet not too 'dirty') way of porting code containing a c开发者_运维百科ouple of lambda expressions with reference-bound variables to pre-C++0x code?
Can this be done in a semi automated way using templates/macros?
Maybe you should take a look at boost::lambda. This should do what you are looking for.
(Disclaimer: I'm linking to my own site.)
About a year ago, I put a few useful macros on a a blog post of mine. I don't know how portable it is, and it's pretty limited. But for simple expressions, it works well.
Note that I haven't found much use for it myself, so it can't be that good :-)
sort(vs.begin(), vs.end(),
YALM(bool,vector<int>&,vector<int>&,return l.size() < r.size() )
);
精彩评论