adjacent_difference
각 요소 및 선행 작업 입력 범위의 연속 된 차이 계산 및 대상 범위 결과 출력 차이점 작업이 다른, 지정 된 이항 연산으로 대체 되는 위치는 일반화 된 프로시저의 결과 계산 합니다.
template<class InputIterator, class OutIterator>
OutputIterator adjacent_difference(
InputIterator _First,
InputIterator _Last,
OutputIterator _Result
);
template<class InputIterator, class OutIterator, class BinaryOperation>
OutputIterator adjacent_difference(
InputIterator _First,
InputIterator _Last,
OutputIterator _Result,
BinaryOperation _Binary_op
);
매개 변수
_First
이항 연산의 입력된 요소가 자신의 해당 선행 작업으로 비교가 되 나 값 쌍에서 다른 작동 하는 입력 범위의 첫 번째 요소의 주소를 지정 하는 반복기를 지정 합니다._Last
이항 연산의 입력된 반복기 주소 요소가 자신의 해당 선행 작업으로 비교가 되 나 값 쌍에서 다른 작동 하는 입력 범위의 마지막 요소를 지정 합니다._Result
대상 범위는 일련의 차이 또는 지정 된 작업의 결과 저장할 수 있는 첫 번째 요소의 주소를 지정 하는 출력 반복기입니다._Binary_op
일반화 된 차이점 보관용 프로시저에서 빼기 작업 교체 작업에 적용 되는 이항 연산
반환 값
출력 반복기 대상 범위의 끝 주소 지정: _Result + (_Last - _First).
설명
출력 반복기 _결과 입력된 반복기로 동일한 반복기를 사용할 수 _First, 있도록 adjacent_difference에서 s를 계산할 수 있습니다.
값의 시퀀스에 대 한 는1, 는2, 는3 첫 번째 템플릿 함수는 입력된 범위에 연속적으로 저장 partial_differences 는1, 는-2 는a3-1 는대상 범위에서 2.
일련의 값에 대 한 는1, 는2, 는3 번째 템플릿 함수는 입력된 범위에 연속적으로 저장 partial_differences 는1, 는2 _Binary_op는1, 는3 _Binary_op는대상 범위에서 2.
이항 연산의 _Binary_op 연관 또는 비가 환 적 될 필요가 없습니다, 작업 순서에 적용 되기 때문에 완전 하 게 지정 됩니다.
adjacent_difference두 폼 관련 있습니다.
양식 중의 하나는 확인 된 반복기를 전달할 경우 adjacent_difference, 동작 확인 된 반복기를 가져옵니다. 선택 되지 않은 반복기를 전달 하는 경우 확인 되지 않은 동작을 볼 수 있습니다.자세한 내용은 확인 된 반복기를 참조하십시오.
예제
// numeric_adj_diff.cpp
// compile with: /EHsc
#include <vector>
#include <list>
#include <numeric>
#include <functional>
#include <iostream>
int main( )
{
using namespace std;
vector<int> V1( 10 ), V2( 10 );
vector<int>::iterator VIter1, VIter2, VIterend, VIterend2;
list <int> L1;
list <int>::iterator LIter1, LIterend, LIterend2;
int t;
for ( t = 1 ; t <= 10 ; t++ )
{
L1.push_back( t * t );
}
cout << "The input list L1 is:\n ( " ;
for ( LIter1 = L1.begin( ) ; LIter1 != L1.end( ) ; LIter1++ )
cout << *LIter1 << " ";
cout << ")." << endl;
// The first member function for the adjacent_differences of
// elements in a list output to a vector
VIterend = adjacent_difference ( L1.begin ( ) , L1.end ( ) ,
V1.begin ( ) );
cout << "Output vector containing adjacent_differences is:\n ( " ;
for ( VIter1 = V1.begin( ) ; VIter1 != VIterend ; VIter1++ )
cout << *VIter1 << " ";
cout << ")." << endl;
// The second member function used to compute
// the adjacent products of the elements in a list
VIterend2 = adjacent_difference ( L1.begin ( ) , L1.end ( ) , V2.begin ( ) ,
multiplies<int>( ) );
cout << "The output vector with the adjacent products is:\n ( " ;
for ( VIter2 = V2.begin( ) ; VIter2 != VIterend2 ; VIter2++ )
cout << *VIter2 << " ";
cout << ")." << endl;
// Computation of adjacent_differences in place
LIterend2 = adjacent_difference ( L1.begin ( ) , L1.end ( ) , L1.begin ( ) );
cout << "In place output adjacent_differences in list L1 is:\n ( " ;
for ( LIter1 = L1.begin( ) ; LIter1 != LIterend2 ; LIter1++ )
cout << *LIter1 << " ";
cout << ")." << endl;
}
Output
The input list L1 is:
( 1 4 9 16 25 36 49 64 81 100 ).
Output vector containing adjacent_differences is:
( 1 3 5 7 9 11 13 15 17 19 ).
The output vector with the adjacent products is:
( 1 4 36 144 400 900 1764 3136 5184 8100 ).
In place output adjacent_differences in list L1 is:
( 1 3 5 7 9 11 13 15 17 19 ).
요구 사항
헤더: <numeric>
네임 스페이스: std