다음을 통해 공유


map::equal_range

나타내는 한 쌍의 반복기를 반환의 lower_bound 키와 upper_bound 키.

pair <const_iterator, const_iterator> equal_range (
   const Key& _Key
) const;
pair <iterator, iterator> equal_range (
   const Key& _Key
);

매개 변수

  • _Key
    검색 되는 지도 요소의 정렬 키를 비교할 인수 키 값입니다.

반환 값

첫 번째 반복기 쌍에 액세스 하려면 pr 멤버 함수에 의해 반환 된 사용 pr. 첫 번째, 하한값 반복기 역참조를 사용 하 고 * (pr.첫 번째).두 번째 반복기 쌍에 액세스 하려면 pr 멤버 함수에 의해 반환 된 사용 pr. 두 번째, 상한 반복기 역참조를 사용 하 고 * (pr.두 번째).

예제

// map_equal_range.cpp
// compile with: /EHsc
#include <map>
#include <iostream>

int main( )
{
   using namespace std; 
   typedef map <int, int, less<int> > IntMap;
   IntMap m1;
   map <int, int> :: const_iterator m1_RcIter;
   typedef pair <int, int> Int_Pair;

   m1.insert ( Int_Pair ( 1, 10 ) );
   m1.insert ( Int_Pair ( 2, 20 ) );
   m1.insert ( Int_Pair ( 3, 30 ) );

   pair <IntMap::const_iterator, IntMap::const_iterator> p1, p2;
   p1 = m1.equal_range( 2 );

   cout << "The lower bound of the element with "
        << "a key of 2 in the map m1 is: "
        << p1.first -> second << "." << endl;

   cout << "The upper bound of the element with "
        << "a key of 2 in the map m1 is: "
        << p1.second -> second << "." << endl;

   // Compare the upper_bound called directly 
   m1_RcIter = m1.upper_bound( 2 );

   cout << "A direct call of upper_bound( 2 ) gives "
        << m1_RcIter -> second << "," << endl
        << " matching the 2nd element of the pair"
        << " returned by equal_range( 2 )." << endl;

   p2 = m1.equal_range( 4 );

   // If no match is found for the key,
   // both elements of the pair return end( )
   if ( ( p2.first == m1.end( ) ) && ( p2.second == m1.end( ) ) )
      cout << "The map m1 doesn't have an element "
           << "with a key less than 40." << endl;
   else
      cout << "The element of map m1 with a key >= 40 is: "
           << p2.first -> first << "." << endl;
}
  
  
  
  

요구 사항

헤더: <map>

네임 스페이스: std

참고 항목

참조

map Class

표준 템플릿 라이브러리