How to get min or max element in a vector of structures in c++, based on some field in the structure?
For example:
struct Size { int width, height; }
vector sizes; ... vector sortedByWidths(sizes); vector sortedByHeights(sizes); sort(sortedByWidths.begin(), sortedByWidths.end(), [](Size s1, Size s2) {return s1.width < s2.width;}); sort(sortedByHeights.begin(), sortedByHeights.end(), [](Size s1, Size s2) {return s1.height< s2.height;});