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

后端 未结 2 1297
梦谈多话
梦谈多话 2021-01-07 22:34

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::v

2条回答
  •  一向
    一向 (楼主)
    2021-01-07 22:43

    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.

提交回复
热议问题