operator< (hash_map)

如果在运算符的左边hash_map对象与右侧,的hash_map对象小于测试。

bool operator<(
   const hash_map <Key, Type, Traits, Allocator>& _Left,
   const hash_map <Key, Type, Traits, Allocator>& _Right
);

参数

  • _Left
    hash_map 类型的对象。

  • _Right
    hash_map 类型的对象。

返回值

true,如果在运算符的左边hash_map比在运算符的右侧hash_map严格小于;否则 false

备注

在hash_map对象之间的比较根据其元素的比较pairwise。 小于两个对象之间的关系于比较的第一对不相等元素。

在Visual C++ .NET 2003中,<hash_map><hash_set> 标头文件的成员中不再标准,命名空间,而是将stdext命名空间。 有关更多信息,请参见 stdext 命名空间

示例

// hash_map_op_lt.cpp
// compile with: /EHsc
#define _DEFINE_DEPRECATED_HASH_CLASSES 0
#include <hash_map>
#include <iostream>

int main( )
{
   using namespace std;
   using namespace stdext;
   hash_map<int, int> hm1, hm2, hm3;
   hash_map <int, int>::iterator hm1_Iter, hm2_Iter, hm3_Iter;   
   int i;
   typedef pair<int, int> Int_Pair;

   for ( i = 1 ; i < 4 ; i++ )
   {
      hm1.insert ( Int_Pair ( i , i ) );
      hm2.insert ( Int_Pair ( i , i + 1 ) );
      hm3.insert ( Int_Pair ( i + 1 , i ) );
   }

   cout  << "The elements of hash_map hm1 are:";
   for ( hm1_Iter= hm1.begin( ) ; hm1_Iter!= hm1.end( ) ; hm1_Iter++)
       cout << "( " << hm1_Iter-> first << ", " << hm1_Iter->second << " ) ";
   cout << "." << endl;

   cout  << "The elements of hash_map hm2 are:";
   for ( hm2_Iter= hm2.begin( ) ; hm2_Iter!= hm2.end( ) ; hm2_Iter++)
       cout << "( " << hm2_Iter-> first << ", " << hm2_Iter->second << " ) ";
   cout << "." << endl;

   cout  << "The elements of hash_map hm3 are:";
   for ( hm3_Iter= hm3.begin( ) ; hm3_Iter!= hm3.end( ) ; hm3_Iter++)
       cout << "( " << hm3_Iter-> first << ", " << hm3_Iter->second << " ) ";
   cout << "." << endl;


   if ( hm1 < hm2 )
      cout << "The hash_map hm1 is less than the hash_map hm2." << endl;
   else
      cout << "The hash_map hm1 is not less than the hash_map hm2." << endl;

   if ( hm1 < hm3 )
      cout << "The hash_map hm1 is less than the hash_map hm3." << endl;
   else
      cout << "The hash_map hm1 is not less than the hash_map hm3." << endl;
}
  
  
  
  
  

要求

标头: <hash_map>

命名空间: stdext

请参见

参考

标准模板库