Penso che si sta cercando std::any_of
, che restituirà una risposta vera/falsa per rilevare se un elemento è in un contenitore (array, vector, deque, ecc)
int val = SOME_VALUE; // this is the value you are searching for
bool exists = std::any_of(std::begin(myArray), std::end(myArray), [&](int i)
{
return i == val;
});
Se si desidera sapere dove si trova l'elemento, std::find
restituirà un iteratore al primo elemento corrispondente ai criteri che fornisci (o un predicato che gli dai).
int val = SOME_VALUE;
int* pVal = std::find(std::begin(myArray), std::end(myArray), val);
if (pVal == std::end(myArray))
{
// not found
}
else
{
// found
}
fonte
2013-10-10 15:08:49
Guarda l'esempio per [ 'std :: find'] (http://www.cplusplus.com/reference/algorithm/find/). – DCoder