multiset::difference_type
要素間の範囲セットの複数の要素数を表すことができる符号付き整数型は、反復子が指す。
typedef typename allocator_type::difference_type difference_type;
解説
difference_type はコンテナーの反復子で減算、乗算して返される型です。difference_type は、通常、反復子範囲 [ _First 間の_First、_Last内の要素数を表すために使用され、_Lastは、_First で、要素のスコープは、で指定された点まで、要素 _Lastが指す要素が含まれます。
difference_type がベクターのようなランダム アクセス コンテナーによって提供されるランダム アクセス反復子によってのみ設定など、元のコンテナーと、双方向の反復子クラスをサポートしていた含む、入力反復子の条件を満たすすべての反復子、反復子の間の減算で使用可能ですがサポートされていることに注意してください。
使用例
// multiset_diff_type.cpp
// compile with: /EHsc
#include <iostream>
#include <set>
#include <algorithm>
int main( )
{
using namespace std;
multiset <int> ms1;
multiset <int>::iterator ms1_Iter, ms1_bIter, ms1_eIter;
ms1.insert( 20 );
ms1.insert( 10 );
ms1.insert( 20 );
ms1_bIter = ms1.begin( );
ms1_eIter = ms1.end( );
multiset <int>::difference_type df_typ5, df_typ10, df_typ20;
df_typ5 = count( ms1_bIter, ms1_eIter, 5 );
df_typ10 = count( ms1_bIter, ms1_eIter, 10 );
df_typ20 = count( ms1_bIter, ms1_eIter, 20 );
// The keys, and hence the elements, of a multiset are not unique
cout << "The number '5' occurs " << df_typ5
<< " times in multiset ms1.\n";
cout << "The number '10' occurs " << df_typ10
<< " times in multiset ms1.\n";
cout << "The number '20' occurs " << df_typ20
<< " times in multiset ms1.\n";
// Count the number of elements in a multiset
multiset <int>::difference_type df_count = 0;
ms1_Iter = ms1.begin( );
while ( ms1_Iter != ms1_eIter)
{
df_count++;
ms1_Iter++;
}
cout << "The number of elements in the multiset ms1 is: "
<< df_count << "." << endl;
}
必要条件
ヘッダー: <set>
名前空間: std