c++11 - C++ using inline function in std::sort -
this question has answer here:
- what lambda expression in c++11? 8 answers
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
Post a Comment