As I understand the problem of std::set_intersection better now, i do not believe anymore that it is a good idea to relax the precondition to make inplace usage possible.Instead I would like to propose and get feedback for following solution:auto remove_missing = [](auto first1, auto last1, auto first2, auto last2, auto comp){return std::remove_if(first1, last1,[&](auto const& elem){ return not std::binary_search(first2, last2, elem, comp); });};