fork(2) download
  1. #include <string>
  2. #include <memory>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <iostream>
  6.  
  7. class Worker {
  8. private:
  9. std::string name;
  10. public:
  11. Worker(std::string n) { name = n; }
  12. std::string getName() { return name; }
  13. };
  14.  
  15. int main()
  16. {
  17. using workers_t = std::unique_ptr<Worker>;
  18. std::vector<workers_t> Workers;
  19. Workers.emplace_back(std::make_unique<Worker>(Worker("Paul")));
  20. Workers.emplace_back(std::make_unique<Worker>(Worker("Anna")));
  21. Workers.emplace_back(std::make_unique<Worker>(Worker("John")));
  22.  
  23. std::sort(std::begin(Workers), std::end(Workers), [](const workers_t& a, const workers_t& b) {
  24. return a->getName() < b->getName();
  25. });
  26.  
  27. for (auto const &worker : Workers)
  28. std::cout << worker->getName() << std::endl;
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0s 15248KB
stdin
Standard input is empty
stdout
Anna
John
Paul