Are Standard Library algorithms allowed to copy predicate arguments?
问题 Suppose we'd like to remove duplicate values from a vector of int s. The usual solution is to sort the vector and erase duplicates with erase-remove idiom. But we need to mantain the order of the elements that will not be removed, so we can't sort. So one might come up with a predicate like this and use with with remove_if algorithm: struct comp { std::set<int> s; comp() : s() {} bool operator()(int i) { return !(s.insert(i)).second; } }; But this will break if predicate object will be copied