Created
August 7, 2019 10:51
-
-
Save insaneyilin/2f6bf0807223390bf535182c34632e1c to your computer and use it in GitHub Desktop.
compare struct using std::tie()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Student { | |
int stu_id; | |
int age; | |
float grade; | |
}; | |
std::vector<Student> students; | |
// fill students vector | |
// ... | |
std::sort(std::begin(students), std::end(students), | |
[](const Student &lhs, const Student &rhs) -> bool { | |
return std::tie(lhs.grade, lhs.stu_id, lhs.age) < | |
std::tie(rhs.grade, rhs.stu_id, rhs.age); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment