hash_set::difference_type

说明说明

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

可用于表示一 hash_set 的元素数在一个范围的组件之间的一个带符号整数类型指向由迭代器。

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 未满足输入迭代的要求,包括双向迭代器选件类由可逆容器支持例如 set 所有迭代器,在迭代之间的减法可用由一个随机访问容器提供的随机访问迭代器只支持,例如向量或、向量、双端队列。

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

示例

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

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

   hash_set <int> hs1;
   hash_set <int>::iterator hs1_Iter, hs1_bIter, hs1_eIter;

   hs1.insert( 20 );
   hs1.insert( 10 );
   hs1.insert( 20 );   // Won't insert as hash_set elements are unique

   hs1_bIter = hs1.begin( );
   hs1_eIter = hs1.end( );

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

   df_typ5 = count( hs1_bIter, hs1_eIter, 5 );
   df_typ10 = count( hs1_bIter, hs1_eIter, 10 );
   df_typ20 = count( hs1_bIter, hs1_eIter, 20 );

   // The keys, and hence the elements, of a hash_set are unique,
   // so there is at most one of a given value
   cout << "The number '5' occurs " << df_typ5
        << " times in hash_set hs1.\n";
   cout << "The number '10' occurs " << df_typ10
        << " times in hash_set hs1.\n";
   cout << "The number '20' occurs " << df_typ20
        << " times in hash_set hs1.\n";

   // Count the number of elements in a hash_set
   hash_set <int>::difference_type  df_count = 0;
   hs1_Iter = hs1.begin( );
   while ( hs1_Iter != hs1_eIter)
   {
      df_count++;
      hs1_Iter++;
   }

   cout << "The number of elements in the hash_set hs1 is: " 
        << df_count << "." << endl;
}
  
  
  
  

要求

标头: <hash_set>

命名空间: stdext

请参见

参考

hash_set Class

标准模板库