find_if

범위에서 지정한 조건을 만족 하는 중 첫 번째 요소의 위치를 찾습니다.

template<class InputIterator, class Predicate>
   InputIterator find_if(
      InputIterator _First, 
      InputIterator _Last, 
      Predicate _Pred
   );

매개 변수

  • _First
    검색할 범위의 첫 번째 요소의 위치 주소 입력된 반복기입니다.

  • _Last
    검색할 위치 하나 과거 최종 요소 범위에 있는 주소 입력된 반복기입니다.

  • _Pred
    검색 되는 요소에 의해 충족 되어야 하는 조건을 정의 하는 조건자 함수의 사용자 정의 개체입니다.단일 인수를 사용 하 고 반환 하는 조건자 true 또는 거짓.

반환 값

조건자에서 지정한 조건에 맞는 범위에서 첫 번째 요소의 주소는 입력된 반복기입니다.

설명

이 템플릿 함수 알고리즘의 일반화 된 찾기, 조건자 교체 "같은 특정 값" 모든 조건자와.

예제

// alg_find_if.cpp
// compile with: /EHsc
#include <list>
#include <algorithm>
#include <iostream>

bool greater10 ( int value )
{
   return value >10;
}

int main( )
{
   using namespace std;

   list <int> L;
   list <int>::iterator Iter;
   list <int>::iterator result;
   
   L.push_back( 5 );
   L.push_back( 10 );
   L.push_back( 15 );
   L.push_back( 20 );
   L.push_back( 10 );

   cout << "L = ( " ;
   for ( Iter = L.begin( ) ; Iter != L.end( ) ; Iter++ )
      cout << *Iter << " ";
   cout << ")" << endl;

   
   result = find_if( L.begin( ), L.end( ), &greater10 );
   if ( result == L.end( ) )
      cout << "There is no element greater than 10 in list L."
           << endl;
   else
   {
      result++;
      cout << "There is an element greater than 10 in list L,"
           << "\n and it is followed by a "
           <<  *(result) << "." << endl;
   }
}
  

요구 사항

헤더: <algorithm>

네임 스페이스: std

참고 항목

참조

find_if (STL Samples)

표준 템플릿 라이브러리