다음을 통해 공유


hash_set::key_comp

참고

이 API는 사용되지 않습니다.unordered_set 클래스를 대신 사용하는 것이 좋습니다.

Retrieves a copy of the hash traits object used to hash and order element key values in a hash_set.

key_compare key_comp( ) const;

반환 값

Returns the function object that a hash_set uses to order its elements, which is the template parameter Traits.

자세한 내용은 Traitshash_set 클래스 항목을 참조하십시오.

설명

The stored object defines the member function:

bool operator(const Key& _xVal, const Key& _yVal);

which returns true if _xVal precedes and is not equal to _yVal in the sort order.

Note that both key_compare and value_compare are synonyms for the template parameter Traits. Both types are provided for the hash_set and hash_multiset classes, where they are identical, for compatibility with the hash_map and hash_multimap classes, where they are distinct.

Visual C++.NET 2003에서, <hash_map><hash_set> 헤더 파일의 멤버는 더 이상 std 네임스페이스에 존재하지 않습니다. 대신 stdext 네임스페이스로 이동되었습니다. 자세한 내용은 stdext 네임스페이스를 참조하십시오.

예제

// hash_set_key_comp.cpp
// compile with: /EHsc
#include <hash_set>
#include <iostream>

int main( )
{
   using namespace std;
   using namespace stdext;
   
   hash_set <int, hash_compare < int, less<int> > >hs1;
   hash_set<int, hash_compare < int, less<int> > >::key_compare kc1
          = hs1.key_comp( ) ;
   bool result1 = kc1( 2, 3 ) ;
   if( result1 == true )
   {
      cout << "kc1( 2,3 ) returns value of true, "
           << "where kc1 is the function object of hs1."
           << endl;
   }
   else
   {
      cout << "kc1( 2,3 ) returns value of false "
           << "where kc1 is the function object of hs1."
        << endl;
   }

   hash_set <int, hash_compare < int, greater<int> > > hs2;
   hash_set<int, hash_compare < int, greater<int> > >::key_compare
         kc2 = hs2.key_comp( ) ;
   bool result2 = kc2( 2, 3 ) ;
   if(result2 == true)
   {
      cout << "kc2( 2,3 ) returns value of true, "
           << "where kc2 is the function object of hs2."
           << endl;
   }
   else
   {
      cout << "kc2( 2,3 ) returns value of false, "
           << "where kc2 is the function object of hs2."
           << endl;
   }
}

Output

kc1( 2,3 ) returns value of true, where kc1 is the function object of hs1.
kc2( 2,3 ) returns value of false, where kc2 is the function object of hs2.

요구 사항

헤더: <hash_set>

네임스페이스: stdext

참고 항목

참조

hash_set 클래스

표준 템플릿 라이브러리