fork download
  1. #include <vector>
  2. #include <string>
  3. #include <iostream>
  4. #include <algorithm>
  5.  
  6. int main() {
  7. struct Entity {
  8. Entity(std::string name, int order)
  9. : Name{name}
  10. , Order{order}
  11. {}
  12.  
  13. std::string Name;
  14. int Order;
  15. };
  16. std::vector<Entity> entities;
  17. entities.emplace_back("Test1", 2);
  18. entities.emplace_back("Test2", 3);
  19. entities.emplace_back("Test3", 1);
  20.  
  21. std::sort(entities.begin(), entities.end(), [](Entity& a, Entity& b) {
  22. return a.Order < b.Order;
  23. });
  24.  
  25. for(auto& entity : entities) {
  26. std::cout << entity.Name << ": " << entity.Order << "\n";
  27. }
  28. }
Success #stdin #stdout 0s 4464KB
stdin
Standard input is empty
stdout
Test3: 1
Test1: 2
Test2: 3