Hello community, Happy New Year!
I came up with interesting macro which allows sort objects by some field. The code is laconic but requires C++11. Macro itself:
#define by(T, x) [](const T& a, const T& b) { return a.x < b.x; }
Usage:
struct Item {
int a, b;
};
sort(arr, arr + N, by(Item, a));
Full example: http://pastebin.com/Cp5ZkwE4.
Happy New Year!