mercredi 31 août 2016

Using the value that any_of finds to use in a return outside lambda

A working piece of code:

std::vector<double>::iterator it = std::find_if(intersections.begin(), intersections.end(), [&](const double i) {return i >= 0;});
if (it != intersections.end())
    return rayOrigin + *(it) * rayDirection);

But I would like to use something like this

Is there a way to capture the i in a clean way (not using a temp variable), that the any_of finds here to use it in the return statement

if (std::any_of(intersections.begin(), intersections.end(), [&](const double i) {return i >= 0;}))
    return rayOrigin + i * rayDirection);

Aucun commentaire:

Enregistrer un commentaire