https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81482
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to kloetzl from comment #2) > I don't think that the runtime cost of the copies is measurable. My bigger > issue is that this quirks exposes the internal behaviour of the algorithm > implementation; In this case the fact that remove_if calls find_if. My > expectation would be that the standard algorithms are opaque. It doesn't expose that it calls find_if, it could call some other internal helper which makes the copies. Just because there are copies doesn't mean find_if is used. And changing the algorithm to make no copies would not make it opaque, because the lack of copies would be observable. As the standard says, whether copies are made or not is unspecified. So if you want to treat them as opaque, don't do something that depends on the internal details, use them as suggested by the note in the standard. > Another solution might be to implement a compiler warning: If a lambda is > mutable, captures by value and gets passed to a standard algorithm, produce > a warning. This will not catch all problematic cases with internal copies of > the predicate but might avoid the biggest pitfalls. That seems far too specific a warning to be useful.