#include <algorithm>
#include <iostream>
#include <iterator>
#include <set>
#include <vector>

int main() {
  std::set<int> v1{7, 2, 3, 4, 5, 6, 7, 8};
  std::set<int> v2{5, 7, 9, 7};
  // sorting is important for lists if we do want all elements of intersections (f.e. if the elements are not unique in both lists)
  // std::sort(v1.begin(), v1.end());
  // std::sort(v2.begin(), v2.end());

  std::set<int> v_intersection;

  std::set_intersection(
      v1.begin(), v1.end(), 
      v2.begin(), v2.end(),
      std::inserter(v_intersection, v_intersection.begin()));
      // std::back_inserter(v_intersection))); // for vector / list

  for (auto n: v_intersection) {
    std::cout << "n: " << n << std::endl;
  }

  std::cout << std::endl;
  return 0;
}
