How to make std::vector from other vector with specific filter?

点点圈 提交于 2020-01-11 04:23:04

问题


I have a std::vector filled with objects. I want to filter and copy all the elements for which some predicate returns true in to a new std::vector.

I've looked at find and search functions but they only return iterators.

I'm using ObjC++ so I can use block functions as well as functors, if it helps. Can't use C++11 functions though.


回答1:


If you have C++11 then use std::copy_if as suggested in Eugen's answer. Otherwise, you can use std::remove_copy_if with appropriate modifications to your predicate's logic.




回答2:


you can use the std::copy_if method. See here.



来源:https://stackoverflow.com/questions/11028266/how-to-make-stdvector-from-other-vector-with-specific-filter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!