I want to check if a value exists in a vector. It is most likely at the end of the vector, does it make sense to use reverse iterators like this:
std::vector<int> v{};
//... add a lot of values ...
const int valueToCheckFor{42};
if (std::any_of(v.crbegin(), v.crend(), [valueToCheckFor](const auto x){ return valueToCheckFor == x; }
or is
if (std::any_of(v.cbegin(), v.cend(), [valueToCheckFor](const auto x){ return valueToCheckFor == x; }
just the same, since the order of execution in std::any_of
is not specified and I'd be better off by using a for-loop?
this is for c++11/c++14
Aucun commentaire:
Enregistrer un commentaire