3 ms·
Easy: std::vector<P> people = { P{"jane", 47}, P{"mary", 71}, P{"john", 65} }; ranges::sort(people, [](auto& x, auto& y){ return x.weight > y.weight;
by Cieplak 9y ago
Easy:
std::vector<P> people = { P{"jane", 47}, P{"mary", 71}, P{"john", 65} };
ranges::sort(people, [](auto& x, auto& y){ return x.weight > y.weight; });
Compile this gist with `c++ -std=c++1z -I range-v3/include`:
https://gist.github.com/cieplak/dcd587c67d989768900e4110e776842c https://gist.github.com/cieplak/dcd587c67d989768900e4110e776...
- joshuamorton 9y agoWhat if two weights are equal, the python code will also sort by name as well ;)