fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <set>
  5. #include <iterator>
  6. using namespace std;
  7.  
  8. template<typename Cont>
  9. Cont diff(Cont const &a, Cont const &b) {
  10. using T = typename Cont::value_type;
  11. set<T> sa(begin(a), end(a)),
  12. sb(begin(b), end(b));
  13.  
  14. Cont result;
  15. set_symmetric_difference(
  16. begin(sa), end(sa),
  17. begin(sb), end(sb),
  18. back_inserter(result));
  19. return result;
  20. }
  21.  
  22. int main() {
  23. vector<int> a {1, 2, 3, 4, 5},
  24. b {1, 3, 6, 7, 4};
  25.  
  26. for(int el: diff(a, b)) {
  27. cout << el << " ";
  28. }
  29. return 0;
  30. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
2 5 6 7