共用方式為


hash_set::difference_type

注意事項注意事項

這個 API 已經過時。這個選項是 unordered_set Class

可以用來表示 hash_set 的元素數目一個範圍的項目之間的帶正負號的整數型別指向的 Iterator。

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

備註

當減去或將透過容器的 Iterator 時, difference_type 為傳回的型別。 difference_type 通常用來表示項目數範圍 [_First, _Last)。 _FirstIterator ,並 _Last,包括項目指向 _First 和項目範圍,但不包括,,項目指向 _Last。

請注意,雖然 difference_type 為符合輸入 Iterator 需求,包括雙向 Iterator 類別由復原容器支援例如集合中所有的 Iterator,在 Iterator 之間的減法可由隨機存取的容器所提供的隨機存取 Iterator 只支援,例如向量或 deque。

在 Visual C++ .NET Pocket PC, <hash_map><hash_set> 標頭檔 (Header File) 的成員不在 std 命名空間,,而是移至 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

標準樣板程式庫