If we need selectively copy elements from one range to another, the standard offers the std::copy_if and std::remove_copy_if algorithms.
Both algorithms accept a predicate, copying elements for which the predicate returns true and false respectively.
Compiler Explorer link: https://compiler-explorer.com/z/bYnhf54G5