list::difference_type
반복기가 가리키는 요소 사이의 범위에 있는 목록의 요소 수를 나타내는 데 사용할 수 있는 부호 있는 정수 형식입니다.
typedef typename Allocator::difference_type difference_type;
설명
difference_type은 컨테이너의 반복기를 빼거나 더할 때 반환되는 형식입니다. difference_type은 일반적으로 _First 및 _Last 반복기 사이의 [_First, _Last] 범위 내 요소 수를 나타내는 데 사용됩니다. 여기에는 _First가 가리키는 요소와 _Last가 가리키는 요소까지의 요소 범위가 포함됩니다(마지막 요소는 포함되지 않음).
입력 반복기 요구 사항을 충족하는 모든 반복기(set 등의 가역 컨테이너에서 지원하는 양방향 반복기 클래스 포함)에 대해 difference_type을 사용할 수는 있지만, 반복기 간의 빼기는 Vector 클래스와 같은 임의 액세스 컨테이너가 제공하는 임의 액세스 반복기를 통해서만 지원됩니다.
예제
// 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