Replace loop with std::find.

No functionality change.
Replace erase loop with std::remove_if.

This avoids unnecessary copies. No functionality change.