https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66418
--- Comment #1 from Marc Glisse <glisse at gcc dot gnu.org> --- Two relevant links to optimize set_intersection (they consider the intersection of k sets, but the case k=2 is still interesting) http://erikdemaine.org/papers/SODA2000/ http://erikdemaine.org/papers/ALENEX2001/ (I am sure there are many others)