hash_multiset::difference_type

备注

此 API 已过时。替代为 unordered_multiset 类

提供两迭代器之间的区别处理同一 hash_multiset 中元素的带符号的整数类型。

typedef list<typename _Traits::value_type, typename _Traits::allocator_type>::difference_type difference_type;

备注

在减去或增长。容器的迭代器,则 difference_type 是返回的类型。 difference_type 通常用于表示元素数处于范围 [_First, _Last) 在迭代器 _First 和 _Last 之间,包括指向由 _First 和范围元素,但不包括,元素指向的 _Last。

请注意,虽然 difference_type 提供足够的所有迭代器可用,输入迭代器要求包含用于双向迭代器类。可逆容器支持如集。 在迭代器之间的减法的随机访问容器提供的随机访问迭代器只支持。向量或 deque。

在Visual C++ .NET 2003中,成员<hash_map><hash_set> 头文件不再在std命名空间,而是已经进入了stdext命名空间。 有关更多信息,请参见 stdext 命名空间

示例

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

int main( )
{
   using namespace std;
   using namespace stdext;

   hash_multiset <int> hms1;
   hash_multiset <int>::iterator hms1_Iter, hms1_bIter, hms1_eIter;

   hms1.insert( 20 );
   hms1.insert( 10 );

   // hash_multiset elements need not be unique
   hms1.insert( 20 );

   hms1_bIter = hms1.begin( );
   hms1_eIter = hms1.end( );

   hash_multiset <int>::difference_type   df_typ5, df_typ10,
        df_typ20;

   df_typ5 = count( hms1_bIter, hms1_eIter, 5 );
   df_typ10 = count( hms1_bIter, hms1_eIter, 10 );
   df_typ20 = count( hms1_bIter, hms1_eIter, 20 );

   // The keys & hence the elements of a hash_multiset
   // need not be unique and may occur multiple times
   cout << "The number '5' occurs " << df_typ5
        << " times in hash_multiset hms1.\n";
   cout << "The number '10' occurs " << df_typ10
        << " times in hash_multiset hms1.\n";
   cout << "The number '20' occurs " << df_typ20
        << " times in hash_multiset hms1.\n";

   // Count the number of elements in a hash_multiset
   hash_multiset <int>::difference_type  df_count = 0;
   hms1_Iter = hms1.begin( );
   while ( hms1_Iter != hms1_eIter)
   {
      df_count++;
      hms1_Iter++;
   }

   cout << "The number of elements in the hash_multiset hms1 is " 
        << df_count << "." << endl;
}
  

要求

Header: <hash_set>

**命名空间:**stdext

请参见

参考

hash_multiset 类

标准模板库