4 ms·
Just anonymous function would make a huge difference. Presently, you have to use boost or create new classes (Yes, you need to write a class for any anonymous f
by d0m 16y ago
Just anonymous function would make a huge difference. Presently, you have to use boost or create new classes (Yes, you need to write a class for any anonymous function! (See Effective Stl, item 46 for more details of why it is recommended)).
So, taken from: http://www2.research.att.com/~bs/C++0xFAQ.html#lambda http://www2.research.att.com/~bs/C++0xFAQ.html#lambda
You could write something like:
void f(vector<Record>& v)
{
vector<int> indices(v.size());
int count = 0;
fill(indices.begin(),indices.end(),[&count](){ return ++count; });
// sort indices in the order determined by the name field of the records:
std::sort(indices.begin(), indices.end(), [&](int a, int b) { return v[a].name<v[b].name; });
// ...
}
- rwmj 16y agoWelcome to ... what? 1970? 1960? How many decades ago did other languages have anonymous functions?
- malkia 16y agoExactly! Now it's time for the assembly language to get anonymous lambdas too :)
- rwmj 16y agoIf only C++ was as useful as the odd bit of assembly programming.
- masklinn 16y agoLisp, 1958. Though technically they were invented in 1936 by Alonzo Church (in his Lambda Calculus).
- extension 16y agoI hope they at least beat Java to it.
- killedbydeath 16y agoThere are function pointers in C and they are used to pass logic into C/C++ functions. They are not anonymous, and are more awkward to use than the new syntax, but they covered many use cases.