引数1,boolを返す関数オブジェクトを用いる.見つかった最初のイテレータを返す.見つからなかった場合は末尾.
例
std::find_if( InputIterator first, InputIterator last, UnaryPredicator p);
例
int main()
{
std::vector<std::string> string_array;
string_array.push_back( "sphere" );
string_array.push_back( "plane" );
string_array.push_back( "axes" );
string_array.push_back( "cylinder" );
std::string name = "sphere";
auto it = std::find_if( string_array.begin(), string_array.end(), [name](std::string str) { return str == name; } );
if( it == string_array.end() )
{
std::cout << name << " is not found in string_array." << std::endl;
}
else
{
std::cout << name << " is found in string_array." << std::endl;
}
}

コメントをかく