c++11 - C++ using inline function in std::sort -


this question has answer here:

i've been learning c++ last few months.in c++ in order pass comparator in std::sort can define comparator function , pass argument sorting method.

bool mycomp(edge a, edge b) { return a.wt > b.wt; } std::sort(arr.begin(), arr.end(), mycomp); 

but wonder whether there more elegant way same thing don't have explicitly define function 1 use. in javascript can same thing passing anonymous function this:

arr.sort(function(a, b) { return a.wt > b.wt; });  

is kind of thing possible in c++ or c++11?

as has been discussed previously, lambdas indeed exist in c++11: what lambda expression in c++11?


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -