Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 couple of lambda expressions with reference-bound variables to pre-C++0x code?

Can this be done in a semi automated way using templates/macros?

like image 642
dcn Avatar asked Jun 27 '11 16:06

dcn


2 Answers

Maybe you should take a look at boost::lambda. This should do what you are looking for.

like image 160
mkaes Avatar answered Nov 08 '22 23:11

mkaes


(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()  )
);
like image 44
Aaron McDaid Avatar answered Nov 08 '22 23:11

Aaron McDaid