次の方法で共有


hash_map::difference_type

[!メモ]

この API は、互換性のために残されています。代わりに unordered_map クラスです。

要素間の範囲のhash_mapの要素数を表すことができる符号付き整数型は、反復子が指す。

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

解説

difference_type はコンテナーの反復子で減算、乗算して返される型です。difference_type は、通常、反復子範囲 >[> _First の間の _First、_Last 内の要素数を表すために使用され、_Lastは、_First で、要素のスコープは、で指定された点まで、要素 _Lastが指す要素が含まれます。

difference_type がベクターのようなランダム アクセス、コンテナーによって提供されるランダム アクセス反復子によってのみ設定など、元のコンテナーと、双方向の反復子クラスをサポートしていた含む、入力反復子の条件を満たすすべての反復子、反復子の間の減算で使用可能ですがサポートされていることに注意してください。

Visual C++ .NET 2003では、<hash_map><hash_set> ヘッダー ファイルのメンバーはstdの名前空間に存在しなくなりましたが、ではなくstdextの名前空間に型。詳細については、「The stdext Namespace」を参照してください。

使用例

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

int main( )
{
   using namespace std;
   using namespace stdext;
   hash_map <int, int> hm1;
   typedef pair <int, int> Int_Pair;

   hm1.insert ( Int_Pair ( 2, 20 ) );
   hm1.insert ( Int_Pair ( 1, 10 ) );
   hm1.insert ( Int_Pair ( 3, 20 ) );

   // The following won't insert, because map keys are unique
   hm1.insert ( Int_Pair ( 2, 30 ) );   

   hash_map <int, int>::iterator hm1_Iter, hm1_bIter, hm1_eIter;   
   hm1_bIter = hm1.begin( );
   hm1_eIter = hm1.end( );

   // Count the number of elements in a hash_map 
   hash_map <int, int>::difference_type  df_count = 0;
   hm1_Iter = hm1.begin( );
   while ( hm1_Iter != hm1_eIter)   
   {
      df_count++;
      hm1_Iter++;
   }

   cout << "The number of elements in the hash_map hm1 is: " 
        << df_count << "." << endl;

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

   cout  << "The values of the mapped elements are:";
   for ( hm1_Iter= hm1.begin( ) ; hm1_Iter!= hm1.end( ) ;
         hm1_Iter++)
      cout << " " << hm1_Iter-> second;
   cout << "." << endl;
}
  
  
  

必要条件

ヘッダー: <hash_map>

名前空間: のstdext

参照

関連項目

hash_map Class

標準テンプレート ライブラリ