Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void lobby_info::sort_users(bool by_name, bool by_relation)
- {
- users_sorted_.clear();
- for(auto& u : users_) {
- users_sorted_.push_back(&u);
- }
- std::sort(users_sorted_.begin(), users_sorted_.end(), [&](const user_info* u1, const user_info* u2) {
- if(by_name && by_relation) {
- return u1->relation < u2->relation || (u1->relation == u2->relation && u1->name < u2->name);
- }
- return (by_name ? u1->name < u2->name : true) && (by_relation ? u1->relation < u2->relation : true);
- });
- }
- ======================================================
- struct user_sorter_name
- {
- bool operator()(const user_info& u1, const user_info& u2)
- {
- return u1.name < u2.name;
- }
- bool operator()(const user_info* u1, const user_info* u2)
- {
- return operator()(*u1, *u2);
- }
- };
- struct user_sorter_relation
- {
- bool operator()(const user_info& u1, const user_info& u2)
- {
- return static_cast<int>(u1.relation) < static_cast<int>(u2.relation);
- }
- bool operator()(const user_info* u1, const user_info* u2)
- {
- return operator()(*u1, *u2);
- }
- };
- struct user_sorter_relation_name
- {
- bool operator()(const user_info& u1, const user_info& u2)
- {
- return static_cast<int>(u1.relation) < static_cast<int>(u2.relation)
- || (u1.relation == u2.relation && u1.name < u2.name);
- }
- bool operator()(const user_info* u1, const user_info* u2)
- {
- return operator()(*u1, *u2);
- }
- };
- void lobby_info::sort_users(bool by_name, bool by_relation)
- {
- users_sorted_.clear();
- for(auto & u : users_)
- {
- users_sorted_.push_back(&u);
- }
- if(by_name) {
- if(by_relation) {
- std::sort(users_sorted_.begin(),
- users_sorted_.end(),
- user_sorter_relation_name());
- } else {
- std::sort(users_sorted_.begin(),
- users_sorted_.end(),
- user_sorter_name());
- }
- } else if(by_relation) {
- std::sort(users_sorted_.begin(),
- users_sorted_.end(),
- user_sorter_relation());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement