jeudi 3 septembre 2015

How to find vector of items in std::vector

if there is vector and we need to find more than one item with the same condition. if we called std::find_if it will return the first appearance of the condition.

 std::vector <int> List{0,1,2,3,4,5,6};
    auto item = find_if(List.begin(), List.end(), [](int x)
    {
        return x > 2;
    }
    );

I know we can use std::for_each and put the condition and the action inside the lambda expression, but I am asking if there is a method which do it itself and return a vector of found items.

Aucun commentaire:

Enregistrer un commentaire