list::difference_type
可以用來表示一個清單項目數目某個範圍的項目之間的帶正負號的整數 (Unsigned Integer) 型別指向的 Iterator。
typedef typename Allocator::difference_type difference_type;
備註
,當減去或加入應用程式的 Iterator 時, difference_type 為傳回的型別。 difference_type 通常用來表示項目數目範圍 [_First, _Last)。 _First Iterator 之間,並 _Last,包括項目指向 _First 和項目的範圍,,但不包含項目,指向 _Last。
請注意,雖然為符合輸入 Iterator 需求,包括雙向 Iterator 可用於類別與集合的可反轉的容器所支援的所有 Iterator,在 Iterator 之間的減法是一種適用於隨機存取容器所提供的隨機存取 Iterator 只支援 difference_type ,例如 向量類別。
範例
// list_diff_type.cpp
// compile with: /EHsc
#include <iostream>
#include <list>
#include <algorithm>
int main( )
{
using namespace std;
list <int> c1;
list <int>::iterator c1_Iter, c2_Iter;
c1.push_back( 30 );
c1.push_back( 20 );
c1.push_back( 30 );
c1.push_back( 10 );
c1.push_back( 30 );
c1.push_back( 20 );
c1_Iter = c1.begin( );
c2_Iter = c1.end( );
list <int>::difference_type df_typ1, df_typ2, df_typ3;
df_typ1 = count( c1_Iter, c2_Iter, 10 );
df_typ2 = count( c1_Iter, c2_Iter, 20 );
df_typ3 = count( c1_Iter, c2_Iter, 30 );
cout << "The number '10' is in c1 collection " << df_typ1 << " times.\n";
cout << "The number '20' is in c1 collection " << df_typ2 << " times.\n";
cout << "The number '30' is in c1 collection " << df_typ3 << " times.\n";
}
需求
標題: <list>
命名空間: std