I am trying to use find_if
in a function with Lambda Expressions. I would like to get the last iterator of the vector, but I am not sure how to write it.
I can get the first iterator with this code. In this code, struct has an index, score, and the lost info. A vector in the code save structs and if an index is multiplies of five, the score is higher than usual. In this code, the first iterator's index is five and the last iterator's index is 25.
struct Recorder
{
Recorder(int idx, float score, bool isLost)
{
this->idx = idx;
this->score = score;
this->isLost = isLost;
}
int idx;
float score;
bool isLost;
};
std::vector<std::shared_ptr<Recorder>> recorders;
for (int i = 0; i < 30; ++i)
{
float score = 0.3;
bool isLost = false;
if (i % 5 == 0 && i != 0) score = 0.8;
std::shared_ptr<Recorder> poseRecord = std::make_shared<Recorder>(i, score, isLost);
recorders.push_back(poseRecord);
}
auto record = std::find_if(recorders.begin(), recorders.end(),
[&](std::shared_ptr<Recorder> r) {
return (r->isLost == false && r->score >= 0.8f);
});
std::cout << "idx : " << (*record)->idx << std::endl;
How can I get the last iterate in this code? (here (*record)->idx
should be 25).
Thanks!
Aucun commentaire:
Enregistrer un commentaire