hash_multimap::hash_multimap

备注

此 API 已过时。另一种方法是 unordered_multimap Class

构造为空或是其他某些 hash_multimap 全部或部分的副本的 hash_multimap。

hash_multimap( );
explicit hash_multimap(
   const Compare& _Comp
);
hash_multimap(
   const Compare& _Comp,
   const Allocator& _Al
);
hash_multimap(
   const hash_multimap& _Right
);
template<class InputIterator>
   hash_multimap(
      InputIterator _First,
      InputIterator _Last
   );
template<class InputIterator>
   hash_multimap(
      InputIterator _First,
      InputIterator _Last,
      const Compare& _Comp
   );
template<class InputIterator>
   hash_multimap(
      InputIterator _First,
      InputIterator _Last,
      const Compare& _Comp,
      const Allocator& _Al
   );
hash_multimap(
   hash_multimap&& _Right
);

参数

Parameter

描述

_Al

为此 hash_multimap 对象将使用的存储为程序选件类,默认为 Allocator

_Comp

类型 const 使用的 Traits 的比较函数按映射的元素,默认为 Traits

_Right

构造的设置是复制的映射。

_First

第一个元素的位置在要复制的元素范围内。

_Last

第一个元素的位置在要复制的元素范围的。

备注

所有构造函数存储的分配器对象的类型管理 hash_multimap 的内存存储,并且可以通过调用 get_allocator之后返回。 分配器参数在所使用的选件类声明和预处理器宏通常忽略替换替换分配器。

所有构造函数初始化它们的 hash_multimap。

所有构造函数存储用于建立在 hash_multimap 键中的一个命令,并可通过调用 key_comp后返回类型 Traits 的函数对象。

指定空的初始 hash_multimap,第二个参数指定比较函数 (_Comp) 的类型用于建立元素和第三的顺序显式指定分配器类型 (_Al) 的前三个构造函数是使用。 关键字 explicit 禁止某些类型的自动类型转换。

第四个构造函数指定 hash_multimap _Right的副本。

接下来的三个构造函数复制范围 [_First,_Last) 的映射随着在指定选件类 Traits 和分配器的比较函数的类型的显式的增加。

最后一个构造函数移动 hash_multimap _Right。

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

示例

// hash_multimap_hash_multimap.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>

int main( )
{
   using namespace std;
   using namespace stdext;
   typedef pair <int, int> Int_Pair;
   hash_multimap <int, int>::iterator hm1_Iter, hm3_Iter, hm4_Iter, 
      hm5_Iter, hm6_Iter;
   hash_multimap <int, int, hash_compare <int, greater<int> > 
      >::iterator hm2_Iter;

   // Create an empty hash_multimap hm0 of key type integer
   hash_multimap <int, int> hm0;

   // Create an empty hash_multimap hm1 with the key comparison
   // function of less than, then insert 4 elements
   hash_multimap <int, int, hash_compare <int, less<int> > > hm1;
   hm1.insert( Int_Pair( 1, 10 ) );
   hm1.insert( Int_Pair( 2, 20 ) );
   hm1.insert( Int_Pair( 3, 30 ) );
   hm1.insert( Int_Pair( 4, 40 ) );

   // Create an empty hash_multimap hm2 with the key comparison
   // function of greater than, then insert 2 elements
   hash_multimap <int, int, hash_compare <int, greater<int> > > hm2;
   hm2.insert( Int_Pair( 1, 10 ) );
   hm2.insert( Int_Pair( 2, 20 ) );

   // Create a hash_multimap hm3 with the 
   // allocator of hash_multimap hm1
   hash_multimap <int, int>::allocator_type hm1_Alloc;
   hm1_Alloc = hm1.get_allocator( );
   hash_multimap <int, int> hm3( hash_compare <int, less<int> > ( ), 
      hm1_Alloc );
   hm3.insert( Int_Pair( 3, 30 ) );

   // Create a copy, hash_multimap hm4, of hash_multimap hm1
   hash_multimap <int, int> hm4( hm1 );

   // Create a hash_multimap hm5 by copying the range hm1[_First, _Last)
   hash_multimap <int, int>::const_iterator hm1_bcIter, hm1_ecIter;
   hm1_bcIter = hm1.begin( );
   hm1_ecIter = hm1.begin( );
   hm1_ecIter++;
   hm1_ecIter++;
   hash_multimap <int, int> hm5( hm1_bcIter, hm1_ecIter );

   // Create a hash_multimap hm6 by copying the range hm4[_First, _Last)
   // and with the allocator of hash_multimap hm2
   hash_multimap <int, int>::allocator_type hm2_Alloc;
   hm2_Alloc = hm2.get_allocator( );
   hash_multimap <int, int> hm6(hm4.begin( ), ++hm4.begin( ), less<int>( ), 
      hm2_Alloc);

   cout << "hm1 = ";
   for ( hm1_Iter = hm1.begin( ); hm1_Iter != hm1.end( ); hm1_Iter++ )
      cout << hm1_Iter -> second << " ";
   cout << endl;
   
   cout << "hm2 = ";
   for ( hm2_Iter = hm2.begin( ); hm2_Iter != hm2.end( ); hm2_Iter++ )
   cout << hm2_Iter -> second << " ";
   cout << endl;

   cout << "hm3 = ";
   for ( hm3_Iter = hm3.begin( ); hm3_Iter != hm3.end( ); hm3_Iter++ )
      cout << hm3_Iter -> second << " ";
   cout << endl;

   cout << "hm4 = ";
   for ( hm4_Iter = hm4.begin( ); hm4_Iter != hm4.end( ); hm4_Iter++ )
      cout << hm4_Iter -> second << " ";
   cout << endl;

   cout << "hm5 = ";
   for ( hm5_Iter = hm5.begin( ); hm5_Iter != hm5.end( ); hm5_Iter++ )
      cout << hm5_Iter -> second << " ";
   cout << endl;

   cout << "hm6 = ";
   for ( hm6_Iter = hm6.begin( ); hm6_Iter != hm6.end( ); hm6_Iter++ )
      cout << hm6_Iter -> second << " ";
   cout << endl;

    // Create a copy, hash_map hm7, of hash_multimap hm1 by moving
    hash_map<MyStr, MyInt, hash_compare<MyStr, less_str> >
        hm7(move(hm1));
    cout << "hm7 =";
    for (hm7_Iter = hm7.begin(); hm7_Iter != hm7.end(); hm7_Iter++)
        cout << " " << hm7_Iter -> second;
    cout << endl;
}

Output

hm1 = 10 20 30 40 
hm2 = 10 20 
hm3 = 30 
hm4 = 10 20 30 40 
hm5 = 10 20 
hm6 = 10 
hm7 = 10 20 30 40

要求

标头: <hash_map>

命名空间: stdext

请参见

参考

hash_multimap Class

标准模板库