fork download
  1. #include <algorithm>
  2. #include <cstdint>
  3. #include <iostream>
  4. #include <string>
  5. #include <tuple>
  6. #include <vector>
  7.  
  8. using namespace std;
  9.  
  10. struct Student {
  11. uint32_t id;
  12. string name;
  13. };
  14.  
  15. bool operator==(const Student& a, const Student& b) {
  16. return tie(a.id, a.name) == tie(b.id, b.name);
  17. }
  18.  
  19. main() {
  20. const auto jane = Student{3, "Jane"};
  21. const auto zippy = Student{1, "Zippy"};
  22. const auto classA = vector<Student>{jane, zippy};
  23. auto allStudents = vector<Student>{{5, "Rod"}, jane, {4, "Freddy"}, zippy, {2, "Bungle"}};
  24. partition(begin(allStudents), end(allStudents), [&](const auto& s){ return find(begin(classA), end(classA), s) == end(classA); });
  25. for (const auto& s : allStudents) cout << s.id << ", " << s.name << "; ";
  26. cout << endl;
  27. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
5, Rod; 2, Bungle; 4, Freddy; 1, Zippy; 3, Jane;