std::vector<vector<float>> tmp = {{1,10,5,4},{2,5,5,1},{3,2,4,3},{4,9,7,8}};
我想按向量值的第4个(最后一个)值对这个向量进行排序。所以结果会是这样的。
{{2,5,5,1},{3,2,4,3},{1,10,5,4},{4,9,7,8}};
解决方案:
std::sort(begin(tmp), end(tmp), [](auto const& inner1, auto const& inner2)
{
// Note: No checking if the sizes are zero, should really be done
return inner1.back() < inner2.back();
});