3 ms·
I often prefer to use lambdas as (named) inline function definitions: auto lessGold = [](const Hero& h1, const Hero& h2) { return h1.inventory().gold
by evanpw 11y ago
I often prefer to use lambdas as (named) inline function definitions:
auto lessGold = [](const Hero& h1, const Hero& h2)
{
return h1.inventory().gold() < h2.inventory().gold();
};
std::sort(heroes.begin(), heroes.end(), lessGold);
- AnimalMuppet 11y agoInteresting. In C++, a variable can have global scope, file scope, class/object scope, or local scope. A function can have global scope, file scope, or class/object scope. This lets you create a function that has local scope.
- doomrobo 11y agoYou can even do that in C (non-standard, of course) using clang with the Blocks extension