Skip to content

Instantly share code, notes, and snippets.

@momchil-velikov
Created December 26, 2016 15:57
Show Gist options
  • Save momchil-velikov/733dde3bebb9dcac22953c6b54f74800 to your computer and use it in GitHub Desktop.
Save momchil-velikov/733dde3bebb9dcac22953c6b54f74800 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
struct S {
int x, y, z;
};
int main() {
std::vector<S> a = {
{1, 2, 3},
{1, 2, 4},
{1, 3, 4},
{1, 3, 1},
{2, 2, 3},
{3, 1, 1},
};
std::sort(begin(a), end(a),
[](const S &a, const S &b) -> bool {
return std::tie(a.x, b.y, a.z) < std::tie(b.x, a.y, b.z);
});
for (const auto &e : a)
std::cout << e.x << " " << e.y << " " << e.z << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment