<numeric> 함수

accumulate

연속 부분 합계를 계산하여 일부 초기 값을 포함하여 지정된 범위의 모든 요소의 합계를 계산합니다. 또는 지정된 이진 작업의 연속 부분 결과의 결과를 계산합니다.

template <class InputIterator, class Type>
Type accumulate(
    InputIterator first,
    InputIterator last,
    Type init);

template <class InputIterator, class Type, class BinaryOperation>
Type accumulate(
    InputIterator first,
    InputIterator last,
    Type init,
    BinaryOperation binary_op);

매개 변수

first
범위의 첫 번째 요소를 binary_op 사용하여 합계를 합산하거나 결합하는 입력 반복기입니다.

last
범위의 마지막 요소를 합계로 처리하거나 binary_op 사용하여 결합하는 입력 반복기입니다. 이는 반복된 누적에 실제로 포함된 최종 요소 이외의 한 위치입니다.

init
binary_op 사용하여 각 요소가 차례로 추가되거나 결합되는 초기 값입니다.

binary_op
지정된 범위의 각 요소와 이전 애플리케이션의 결과에 적용할 이진 작업입니다.

반환 값

첫 번째 템플릿 함수에 대해 지정된 범위의 init 및 모든 요소의 합계 또는 두 번째 템플릿 함수의 경우 합계 작업 대신 이진 연산 binary_op 적용한 결과를 (*PartialResult, in_iter)에 적용합니다. 여기서 PartialResult는 이전 연산 애플리케이션의 결과이며 in_iter 범위의 다음 요소를 가리키는 반복기입니다.

설명

초기 값은 범위가 비어 있을 때 잘 정의된 결과가 있는지 확인하고, 이 경우 init 가 반환됩니다. 이진 연산은 연관성이거나 통근적일 필요가 없습니다. 결과는 초기 값 init로 초기화된 다음 결과 = binary_op(결과, in_iter)는 범위를 통해 반복적으로 계산됩니다. 여기서 in_iter 범위의 각 연속 요소를 가리키는 반복기입니다. 범위는 유효해야 하며 복잡성은 범위 크기에 따라 선형입니다. 반복 중에 닫기가 가능하도록 하려면 이진 연산자의 반환 형식을 Type으로 변환할 수 있어야 합니다.

예시

// numeric_accum.cpp
// compile with: /EHsc
#include <vector>
#include <numeric>
#include <functional>
#include <iostream>

int main( )
{
   using namespace std;

   vector <int> v1, v2(20);
   vector <int>::iterator iter1, iter2;

   int i;
   for (i = 1; i < 21; i++)
   {
      v1.push_back(i);
   }

   cout << "The original vector v1 is:\n ( " ;
   for (iter1 = v1.begin(); iter1 != v1.end(); iter1++)
      cout << *iter1 << " ";
   cout << ")." << endl;

   // The first member function for the accumulated sum
   int total;
   total = accumulate(v1.begin(), v1.end(), 0);

   cout << "The sum of the integers from 1 to 20 is: "
        << total << "." << endl;

   // Constructing a vector of partial sums
   int j = 0, partotal;
   for (iter1 = v1.begin(); iter1 != v1.end(); iter1++)
   {
      partotal = accumulate(v1.begin(), iter1 + 1, 0);
      v2[j] = partotal;
      j++;
   }

   cout << "The vector of partial sums is:\n ( " ;
   for (iter2 = v2.begin(); iter2 != v2.end(); iter2++)
      cout << *iter2 << " ";
   cout << ")." << endl << endl;

   // The second member function for the accumulated product
   vector <int> v3, v4(10);
   vector <int>::iterator iter3, iter4;

   int s;
   for (s = 1; s < 11; s++)
   {
      v3.push_back(s);
   }

   cout << "The original vector v3 is:\n ( " ;
   for (iter3 = v3.begin(); iter3 != v3.end(); iter3++)
      cout << *iter3 << " ";
   cout << ")." << endl;

   int ptotal;
   ptotal = accumulate(v3.begin(), v3.end(), 1, multiplies<int>());

   cout << "The product of the integers from 1 to 10 is: "
        << ptotal << "." << endl;

   // Constructing a vector of partial products
   int k = 0, ppartotal;
   for (iter3 = v3.begin(); iter3 != v3.end(); iter3++) {
      ppartotal = accumulate(v3.begin(), iter3 + 1, 1, multiplies<int>());
      v4[k] = ppartotal;
      k++;
   }

   cout << "The vector of partial products is:\n ( " ;
   for (iter4 = v4.begin(); iter4 != v4.end(); iter4++)
      cout << *iter4 << " ";
   cout << ")." << endl;
}
The original vector v1 is:
( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ).
The sum of the integers from 1 to 20 is: 210.
The vector of partial sums is:
( 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190 210 ).

The original vector v3 is:
( 1 2 3 4 5 6 7 8 9 10 ).
The product of the integers from 1 to 10 is: 3628800.
The vector of partial products is:
( 1 2 6 24 120 720 5040 40320 362880 3628800 ).

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);

template <class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
ForwardIterator2 adjacent_difference(
    ExecutionPolicy&& exec,
    ForwardIterator1 first,
    ForwardIterator1 last,
    ForwardIterator2 result);

template <class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class BinaryOperation>
ForwardIterator2 adjacent_difference(
    ExecutionPolicy&& exec,
    ForwardIterator1 first,
    ForwardIterator1 last,
    ForwardIterator2 result,
    BinaryOperation binary_op);

매개 변수

exec
실행 정책입니다.

first
입력 범위에서 해당 선행 작업과 차별화해야 하거나 지정된 다른 이진 작업에서 값 쌍을 처리해야 하는 첫 번째 요소를 주소 지정하는 입력 반복기입니다.

last
입력 범위에서 해당 선행 작업과 차별화해야 하거나 지정된 다른 이진 작업에서 값 쌍을 처리해야 하는 마지막 요소를 주소 지정하는 입력 반복기입니다.

result
일련의 차이 또는 지정된 작업의 결과를 저장할 대상 범위의 첫 번째 요소를 주소 지정하는 출력 반복기입니다.

binary_op
일반화된 작업에 적용할 이진 연산으로, 차이점 보관 절차에서 빼기 연산을 대체합니다.

반환 값

대상 범위의 끝을 주소 지정하는 출력 반복기입니다 result . + (last - first).

설명

출력 반복기 결과는 입력 반복기와 동일한 반복기가 될 수 있으므로 adjacent_difference 값을 그대로 계산할 수 있습니다.

입력 범위에서 1, 2, 3 값 시퀀스의 경우 첫 번째 템플릿 함수는 연속 adjacent_difference 1, 2 - a 1, a3- a2를 대상 범위에 저장합니다.

입력 범위에서 1, 2, 3 값 시퀀스의 경우 두 번째 템플릿 함수는 연속 adjacent_difference 1, 2 binary_op1, 3 binary_op2를 대상 범위에 저장합니다.

적용된 작업의 순서가 지정되므로 이진 작업 binary_op 결합 또는 통근이 필요하지 않습니다.

예시

// 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;
}

exclusive_scan

초기 값이 지정된 범위에 대해 지정된 이진 연산자 또는 std::plus<>() 이진 연산자를 사용하여 배타적인 접두사 합계 연산을 계산합니다. 지정된 대상에서 시작하는 범위에 결과를 씁니다. 배타적 접두사 합계는 n번째 입력 요소가 n번째 합계에 포함되지 않음을 의미합니다. 실행 정책 인수를 포함하는 오버로드는 지정된 정책에 따라 실행됩니다.

template<class InputIterator, class OutputIterator, class Type>
OutputIterator exclusive_scan(
    InputIterator first,
    InputIterator last,
    OutputIterator result,
    Type init);

template<class InputIterator, class OutputIterator, class Type, class BinaryOperation>
OutputIterator exclusive_scan(
    InputIterator first,
    InputIterator last,
    OutputIterator result,
    Type init,
    BinaryOperation binary_op);

template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class Type>
ForwardIterator2 exclusive_scan(
    ExecutionPolicy&& exec,
    ForwardIterator1 first,
    ForwardIterator1 last,
    ForwardIterator2 result,
    Type init);

template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class Type, class BinaryOperation>
ForwardIterator2 exclusive_scan(
    ExecutionPolicy&& exec,
    ForwardIterator1 first,
    ForwardIterator1 last,
    ForwardIterator2 result,
    Type init,
    BinaryOperation binary_op);

매개 변수

exec
실행 정책입니다.

first
범위의 첫 번째 요소를 binary_op 사용하여 합계를 합산하거나 결합하는 입력 반복기입니다.

last
범위의 마지막 요소를 합계로 처리하거나 binary_op 사용하여 결합하는 입력 반복기입니다. 이는 반복된 누적에 실제로 포함된 최종 요소 이외의 한 위치입니다.

result
첫 번째 요소에 대한 일련의 합계 또는 지정된 작업의 결과를 저장할 대상 범위의 주소를 지정하는 출력 반복기입니다.

init
binary_op 사용하여 각 요소가 차례로 추가되거나 결합되는 초기 값입니다.

binary_op
지정된 범위의 각 요소와 이전 애플리케이션의 결과에 적용할 이진 작업입니다.

반환 값

대상 범위의 끝( 결과 + (마지막 - 첫 번째)의 주소를 지정하는 출력 반복기입니다.

Gcd

정수 m과 n의 가장 큰 공통 수수를 계산합니다.

template <class M, class N>
constexpr common_type_t<M,N> gcd(M m, N n);

매개 변수

m, n
정수 계열 형식의 값입니다.

반환 값

m과 n의 절대값 중 가장 큰 공통 수수를 반환하고, mn이 모두 0이면 0을 반환합니다. m 또는 n의 절대값을 형식common_type_t<M,N>값으로 나타낼 수 없는 경우 결과는 정의되지 않습니다.

inclusive_scan

초기 값이 지정된 범위에 대해 지정된 이진 연산자 또는 std::plus<>() 이진 연산자를 사용하여 포괄 접두사 합계 연산을 계산합니다. 지정된 대상에서 시작하는 범위에 결과를 씁니다. 포괄 접두사 합계는 n번째 입력 요소가 n번째 합계에 포함됨을 의미합니다. 실행 정책 인수를 포함하는 오버로드는 지정된 정책에 따라 실행됩니다.

template<class InputIterator, class OutputIterator>
OutputIterator inclusive_scan(
    InputIterator first,
    InputIterator last,
    OutputIterator result);

template<class InputIterator, class OutputIterator, class BinaryOperation>
OutputIterator inclusive_scan(
    InputIterator first,
    InputIterator last,
    OutputIterator result,
    BinaryOperation binary_op);

template<class InputIterator, class OutputIterator, class BinaryOperation, class Type>
OutputIterator inclusive_scan(
    InputIterator first,
    InputIterator last,
    OutputIterator result,
    BinaryOperation binary_op,
    Type init);

template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
ForwardIterator2 inclusive_scan(
    ExecutionPolicy&& exec,
    ForwardIterator1 first,
    ForwardIterator1 last,
    ForwardIterator2 result);

template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class BinaryOperation>
ForwardIterator2 inclusive_scan(
    ExecutionPolicy&& exec,
    ForwardIterator1 first,
    ForwardIterator1 last,
    ForwardIterator2 result,
    BinaryOperation binary_op);

template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
class BinaryOperation, class Type>
ForwardIterator2 inclusive_scan(
    ExecutionPolicy&& exec,
    ForwardIterator1 first,
    ForwardIterator1 last,
    ForwardIterator2 result,
    BinaryOperation binary_op,
    Type init);

매개 변수

exec
실행 정책입니다.

first
범위의 첫 번째 요소를 binary_op 사용하여 합계를 합산하거나 결합하는 입력 반복기입니다.

last
범위의 마지막 요소를 합계로 처리하거나 binary_op 사용하여 결합하는 입력 반복기입니다. 이는 반복된 누적에 실제로 포함된 최종 요소 이외의 한 위치입니다.

result
첫 번째 요소에 대한 일련의 합계 또는 지정된 작업의 결과를 저장할 대상 범위의 주소를 지정하는 출력 반복기입니다.

init
binary_op 사용하여 각 요소가 차례로 추가되거나 결합되는 초기 값입니다.

binary_op
지정된 범위의 각 요소와 이전 애플리케이션의 결과에 적용할 이진 작업입니다.

반환 값

대상 범위의 끝( 결과 + (마지막 - 첫 번째)의 주소를 지정하는 출력 반복기입니다.

inner_product

두 범위의 요소 전체의 곱의 합을 계산하여 지정된 초기값에 추가하거나 합 및 곱 이진 연산을 지정된 다른 이진 연산으로 대체한 일반화된 절차의 결과를 계산합니다.

template <class InputIterator1, class InputIterator2, class Type>
Type inner_product(
    InputIterator1   first1,
    InputIterator1   last1,
    InputIterator2   first2,
    Type             init);

template <class InputIterator1, class InputIterator2, class Type, class BinaryOperation1, class BinaryOperation2>
Type inner_product(
    InputIterator1   first1,
    InputIterator1   last1,
    InputIterator2   first2,
    Type             init,
    BinaryOperation1 binary_op1,
    BinaryOperation2 binary_op2);

매개 변수

first1
두 번째 범위와의 일반화된 내부 곱 또는 내부 곱을 계산할 첫 번째 범위의 첫 번째 요소 주소를 지정하는 입력 반복기입니다.

last1
두 번째 범위와의 일반화된 내부 곱 또는 내부 곱을 계산할 첫 번째 범위의 마지막 번째 요소 주소를 지정하는 입력 반복기입니다.

first2
첫 번째 범위와의 일반화된 내부 곱 또는 내부 곱을 계산할 두 번째 범위의 첫 번째 요소 주소를 지정하는 입력 반복기입니다.

init
범위 간의 내부 곱 또는 일반화된 내부 곱을 더할 초기값입니다.

binary_op1
내부 곱 일반화에서 요소별 곱에 적용되는 합계의 내부 곱 연산을 대체하는 이진 연산입니다.

binary_op2
내부 곱 일반화에서 곱하기의 내부 곱 요소별 연산을 대체하는 이진 연산입니다.

반환 값

첫 번째 구성원 함수는 요소별 곱의 합을 반환하고 해당 합을 지정된 초기값에 더합니다. 따라서 값 ai 및 bi의 범위에 대해 이 함수는 다음 결과를 반환합니다.

init + (a1 * b1) + (a2 * b2) + + (an * b n)

init를 init +(ai * bi)로 반복적으로 바꿔

두 번째 구성원 함수는 다음 결과를 반환합니다.

initbinary_op1 (a1 binary_op2b1) binary_op1 (a2 binary_op2b2) binary_op1 ... binary_op1(n binary_op2bn)

init를 initbinary_op1(i binary_op2 bi)로 반복적으로 바꿔

설명

초기 값은 범위가 비어 있을 때 잘 정의된 결과가 있는지 확인합니다. 이 경우 init 가 반환됩니다. 이진 작업은 연관성 또는 통근이 될 필요가 없습니다. 범위는 유효해야 하며 복잡성은 범위 크기에 따라 선형입니다. 반복 중에 닫기가 가능하도록 하려면 이진 연산자의 반환 형식을 Type으로 변환할 수 있어야 합니다.

예시

// numeric_inner_prod.cpp
// compile with: /EHsc
#include <vector>
#include <list>
#include <numeric>
#include <functional>
#include <iostream>

int main()
{
   using namespace std;

   vector <int> v1, v2(7), v3(7);
   vector <int>::iterator iter1, iter2, iter3;

   int i;
   for (i = 1; i <= 7; i++)
   {
      v1.push_back(i);
   }

   cout << "The original vector v1 is:\n ( " ;
   for (iter1 = v1.begin(); iter1 != v1.end(); iter1++)
      cout << *iter1 << " ";
   cout << ")." << endl;

   list <int> l1, l2(7);
   list <int>::iterator lIter1, lIter2;

   int t;
   for (t = 1; t <= 7; t++)
   {
      l1.push_back(t);
   }

   cout << "The original list l1 is:\n ( " ;
   for (lIter1 = l1.begin(); lIter1 != l1.end(); lIter1++)
      cout << *lIter1 << " ";
   cout << ")." << endl;

   // The first member function for the inner product
   int inprod;
   inprod = inner_product(v1.begin(), v1.end(), l1.begin(), 0);

   cout << "The inner_product of the vector v1 and the list l1 is: "
        << inprod << "." << endl;

   // Constructing a vector of partial inner_products between v1 & l1
   int j = 0, parinprod;
   for (iter1 = v1.begin(); iter1 != v1.end(); iter1++) {
      parinprod = inner_product(v1.begin(), iter1 + 1, l1.begin(), 0);
      v2[j] = parinprod;
      j++;
   }

   cout << "Vector of partial inner_products between v1 & l1 is:\n ( " ;
   for (iter2 = v2.begin(); iter2 != v2.end(); iter2++)
      cout << *iter2 << " ";
   cout << ")." << endl << endl;

   // The second member function used to compute
   // the product of the element-wise sums
   int inprod2;
   inprod2 = inner_product (v1.begin(), v1.end(),
      l1.begin(), 1, multiplies<int>(), plus<int>());

   cout << "The sum of the element-wise products of v1 and l1 is: "
        << inprod2 << "." << endl;

   // Constructing a vector of partial sums of element-wise products
   int k = 0, parinprod2;
   for (iter1 = v1.begin(); iter1 != v1.end(); iter1++)
   {
      parinprod2 =
         inner_product(v1.begin(), iter1 + 1, l1.begin(), 1,
         multiplies<int>(), plus<int>());
      v3[k] = parinprod2;
      k++;
   }

   cout << "Vector of partial sums of element-wise products is:\n ( " ;
   for (iter3 = v3.begin(); iter3 != v3.end(); iter3++)
      cout << *iter3 << " ";
   cout << ")." << endl << endl;
}

iota

첫 번째 요소부터 시작하여 간격[first, last)의 각 요소에 해당 값(value++)의 연속된 증분으로 채우는 시작 값을 저장합니다.

template <class ForwardIterator, class Type>
void iota(ForwardIterator first, ForwardIterator last, Type value);

매개 변수

first
채울 범위의 첫 번째 요소를 주소 지정하는 입력 반복기입니다.

last
채울 범위의 마지막 요소를 주소 지정하는 입력 반복기입니다.

value
첫 번째 요소에 저장하고 이후 요소에 대해 연속적으로 증분할 시작 값입니다.

예시

다음 예제에서는 random_shuffle 함수를 사용할 수 있도록 정수 list를 채운 다음 listvector를 채우는 iota 함수의 몇 가지 사용 방법을 보여 줍니다.

// compile by using: cl /EHsc /nologo /W4 /MTd
#include <algorithm>
#include <numeric>
#include <list>
#include <vector>
#include <iostream>

using namespace std;

int main(void)
{
    list <int> intList(10);
    vector <list<int>::iterator> intVec(intList.size());

    // Fill the list
    iota(intList.begin(), intList.end(), 0);

    // Fill the vector with the list so we can shuffle it
    iota(intVec.begin(), intVec.end(), intList.begin());

    random_shuffle(intVec.begin(), intVec.end());

    // Output results
    cout << "Contents of the integer list: " << endl;
    for (auto i: intList) {
        cout << i << ' ';
    }
    cout << endl << endl;

    cout << "Contents of the integer list, shuffled by using a vector: " << endl;
    for (auto i: intVec) {
        cout << *i << ' ';
    }
    cout << endl;
}

Lcm

template <class M, class N>
constexpr common_type_t<M,N> lcm(M m, N n);

partial_sum

첫 번째 요소부터 n번째 요소까지 입력 범위의 일련의 합계를 계산하고 각 합계의 결과를 대상 범위의 n번째 요소에 저장합니다. 또는 합계 연산이 지정된 다른 이진 작업으로 대체되는 일반화된 프로시저의 결과를 계산합니다.

template <class InputIterator, class OutIt>
OutputIterator partial_sum(
    InputIterator first,
    InputIterator last,
    OutputIterator result);

template <class InputIterator, class OutIt, class Fn2>
OutputIterator partial_sum(
    InputIterator first,
    InputIterator last,
    OutputIterator result,
    BinaryOperation binary_op);

매개 변수

first
지정된 이진 연산에 따라 부분적으로 합을 계산하거나 결합할 범위의 첫 번째 요소를 주소 지정하는 입력 반복기입니다.

last
반복된 누적에 실제로 포함된 마지막 요소 하나 다음 위치의 지정된 이진 연산에 따라 부분적으로 합을 계산하거나 결합할 범위의 마지막 요소를 주소 지정하는 입력 반복기입니다.

result
일련의 부분 합계를 저장할 대상 범위의 첫 번째 요소 또는 지정된 이진 작업의 연속 결과를 처리하는 출력 반복기입니다.

binary_op
부분 합계 프로시저의 합계 연산을 대체하여 일반화된 작업에 적용할 이진 연산입니다.

반환 값

대상 범위의 끝( 결과 + (마지막 - 첫 번째)의 주소를 지정하는 출력 반복기입니다.

설명

출력 반복기 결과는 부분 합계를 계산할 수 있도록 먼저 입력 반복기와 동일한 반복기가 될 수 있습니다.

시퀀스의 경우 1, a2, ... x, 입력 범위에서 첫 번째 템플릿 함수는 대상 범위에 연속 부분 합계를 저장합니다. n번째 요소는 (1 + a2 + a3 + ... + n)에 의해 제공됩니다.

입력 범위에서 1, 2, 3 값 시퀀스의 경우 두 번째 템플릿 함수는 연속 부분 결과를 대상 범위에 저장합니다. n번째 요소는 (...)에 의해 지정됩니다. ((a1 binary_opa2) binary_opa3) binary_op ... ) binary_op n).

적용된 작업의 순서가 지정되므로 이진 작업 binary_op 결합 또는 통근이 필요하지 않습니다.

예시

// numeric_partial_sum.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;

   int t;
   for ( t = 1 ; t <= 10 ; t++ )
   {
      L1.push_back( 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 partial sums of
   // elements in a list output to a vector
   VIterend = partial_sum ( L1.begin ( ) , L1.end ( ) ,
      V1.begin ( ) );

   cout << "The output vector containing the partial sums is:\n ( " ;
   for ( VIter1 = V1.begin( ) ; VIter1 != VIterend ; VIter1++ )
      cout << *VIter1 << " ";
   cout << ")." << endl;

   // The second member function used to compute
   // the partial product of the elements in a list
   VIterend2 = partial_sum ( L1.begin ( ) , L1.end ( ) , V2.begin ( ) ,
      multiplies<int>( ) );

   cout << "The output vector with the partial products is:\n ( " ;
   for ( VIter2 = V2.begin( ) ; VIter2 != VIterend2 ; VIter2++ )
      cout << *VIter2 << " ";
   cout << ")." << endl;

   // Computation of partial sums in place
   LIterend = partial_sum ( L1.begin ( ) , L1.end ( ) , L1.begin ( ) );
   cout << "The in place output partial_sum list L1 is:\n ( " ;
   for ( LIter1 = L1.begin( ) ; LIter1 != LIterend ; LIter1++ )
      cout << *LIter1 << " ";
   cout << ")." << endl;
}

reduce

임의의 순열 순서로 합계를 계산하여 일부 초기 값을 포함하여 지정된 범위의 모든 요소를 줄입니다. 또는 지정된 이진 작업의 결과를 계산하여 줄입니다. 실행 정책 인수를 포함하는 오버로드는 지정된 정책에 따라 실행됩니다.

template<class InputIterator>
typename iterator_traits<InputIterator>::value_type reduce(
    InputIterator first,
    InputIterator last);

template<class InputIterator, class Type>
Type reduce(
    InputIterator first,
    InputIterator last,
    Type init);

template<class InputIterator, class Type, class BinaryOperation>
Type reduce(
    InputIterator first,
    InputIterator last,
    Type init,
    BinaryOperation binary_op);

template<class ExecutionPolicy, class ForwardIterator>
typename iterator_traits<ForwardIterator>::value_type reduce(
    ExecutionPolicy&& exec,
    ForwardIterator first,
    ForwardIterator last);

template<class ExecutionPolicy, class ForwardIterator, class Type>
Type reduce(
    ExecutionPolicy&& exec,
    ForwardIterator first,
    ForwardIterator last,
    Type init);

template<class ExecutionPolicy, class ForwardIterator, class Type, class BinaryOperation>
Type reduce(
    ExecutionPolicy&& exec,
    ForwardIterator first,
    ForwardIterator last,
    Type init,
    BinaryOperation binary_op);

매개 변수

exec
실행 정책입니다.

first
범위의 첫 번째 요소를 binary_op 사용하여 합계를 합산하거나 결합하는 입력 반복기입니다.

last
범위의 마지막 요소를 합계로 처리하거나 binary_op 사용하여 결합하는 입력 반복기입니다. 이는 반복된 누적에 실제로 포함된 최종 요소 이외의 한 위치입니다.

result
첫 번째 요소에 대한 일련의 합계 또는 지정된 작업의 결과를 저장할 대상 범위의 주소를 지정하는 출력 반복기입니다.

init
binary_op 사용하여 각 요소가 차례로 추가되거나 결합되는 초기 값입니다.

binary_op
지정된 범위의 각 요소와 이전 애플리케이션의 결과에 적용할 이진 작업입니다.

반환 값

binary_op std::plus<>() 또는 init 및 지정된 범위의 모든 요소를 (*PartialResult, in_iter)에 적용한 결과입니다. 여기서 PartialResult는 이전 연산 애플리케이션의 결과이며, in_iter 범위의 일부 요소를 가리키는 반복기입니다. init를 지정하지 않는 오버로드에서 사용되는 init 값은 동일합니다typename iterator_traits<InputIterator>::value_type{}.

설명

reduce동작은 binary_op 결합적이고 커밋되지 않는 한 비결정적입니다. 동작은 binary_op 요소를 수정하거나 [첫 번째, 마지막] 간격의 반복기를 무효화하는 경우 정의되지 않습니다.

transform_exclusive_scan

지정된 단항 연산자를 사용하여 범위의 요소를 변환한 다음, 초기 값이 지정된 범위에서 지정된 이진 연산자 또는 지정된 이진 연산자를 사용하여 std::plus<>() 배타적 접두사 합계 연산을 계산합니다. 지정된 대상에서 시작하는 범위에 결과를 씁니다. 배타적 접두사 합계는 n번째 입력 요소가 n번째 합계에 포함되지 않음을 의미합니다. 실행 정책 인수를 포함하는 오버로드는 지정된 정책에 따라 실행됩니다. 합계는 임의의 순서로 수행될 수 있습니다.

template<class InputIterator, class OutputIterator, class Type, class BinaryOperation, class UnaryOperation>
OutputIterator transform_exclusive_scan(
    InputIterator first,
    InputIterator last,
    OutputIterator result,
    Type init,
    BinaryOperation binary_op,
    UnaryOperation unary_op);

template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class Type, class BinaryOperation, class UnaryOperation>
ForwardIterator2 transform_exclusive_scan(
    ExecutionPolicy&& exec,
    ForwardIterator1 first,
    ForwardIterator1 last,
    ForwardIterator2 result,
    Type init,
    BinaryOperation binary_op,
    UnaryOperation unary_op);

매개 변수

exec
실행 정책입니다.

first
범위의 첫 번째 요소를 binary_op 사용하여 합계를 합산하거나 결합하는 입력 반복기입니다.

last
범위의 마지막 요소를 합계로 처리하거나 binary_op 사용하여 결합하는 입력 반복기입니다. 이는 반복된 누적에 실제로 포함된 최종 요소 이외의 한 위치입니다.

result
첫 번째 요소에 대한 일련의 합계 또는 지정된 작업의 결과를 저장할 대상 범위의 주소를 지정하는 출력 반복기입니다.

init
binary_op 사용하여 각 요소가 차례로 추가되거나 결합되는 초기 값입니다.

binary_op
지정된 범위의 각 요소와 이전 애플리케이션의 결과에 적용할 이진 작업입니다.

unary_op
지정된 범위의 각 요소에 적용할 단항 연산입니다.

transform_inclusive_scan

지정된 단항 연산자를 사용하여 범위의 요소를 변환한 다음, 초기 값이 지정된 범위에 대해 지정된 이진 연산자 또는 이진 연산자를 사용하여 std::plus<>() 포괄 접두사 합계 연산을 계산합니다. 지정된 대상에서 시작하는 범위에 결과를 씁니다. 포괄 접두사 합계는 n번째 입력 요소가 n번째 합계에 포함됨을 의미합니다. 실행 정책 인수를 포함하는 오버로드는 지정된 정책에 따라 실행됩니다. 합계는 임의의 순서로 수행될 수 있습니다.

template<class InputIterator, class OutputIterator, class BinaryOperation, class UnaryOperation>
OutputIterator transform_inclusive_scan(
    InputIterator first,
    InputIterator last,
    OutputIterator result,
    BinaryOperation binary_op,
    UnaryOperation unary_op);

template<class InputIterator, class OutputIterator, class BinaryOperation, class UnaryOperation, class Type>
OutputIterator transform_inclusive_scan(
    InputIterator first,
    InputIterator last,
    OutputIterator result,
    BinaryOperation binary_op,
    UnaryOperation unary_op,
    Type init);

template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class BinaryOperation, class UnaryOperation>
ForwardIterator2 transform_inclusive_scan(
    ExecutionPolicy&& exec,
    ForwardIterator1 first,
    ForwardIterator1 last,
    ForwardIterator2 result,
    BinaryOperation binary_op,
    UnaryOperation unary_op);

template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class BinaryOperation, class UnaryOperation, class Type>
ForwardIterator2 transform_inclusive_scan(
    ExecutionPolicy&& exec,
    ForwardIterator1 first,
    ForwardIterator1 last,
    ForwardIterator2 result,
    BinaryOperation binary_op,
    UnaryOperation unary_op,
    Type init);

매개 변수

exec
실행 정책입니다.

first
범위의 첫 번째 요소를 binary_op 사용하여 합계를 합산하거나 결합하는 입력 반복기입니다.

last
범위의 마지막 요소를 합계로 처리하거나 binary_op 사용하여 결합하는 입력 반복기입니다. 이는 반복된 누적에 실제로 포함된 최종 요소 이외의 한 위치입니다.

result
첫 번째 요소에 대한 일련의 합계 또는 지정된 작업의 결과를 저장할 대상 범위의 주소를 지정하는 출력 반복기입니다.

binary_op
지정된 범위의 각 요소와 이전 애플리케이션의 결과에 적용할 이진 작업입니다.

unary_op
지정된 범위의 각 요소에 적용할 단항 연산입니다.

init
binary_op 사용하여 각 요소가 차례로 추가되거나 결합되는 초기 값입니다.

transform_reduce

요소 범위를 변환한 다음 변환된 요소를 임의 순서로 줄이는 functor를 적용합니다. 효과적으로, transform 다음에 reduce.

template<class InputIterator1, class InputIterator2, class Type>
Type transform_reduce(
    InputIterator1 first1,
    InputIterator1 last1,
    InputIterator2 first2,
    Type init);

template<class InputIterator1, class InputIterator2, class Type, class BinaryOperation1, class BinaryOperation2>
Type transform_reduce(
    InputIterator1 first1,
    InputIterator1 last1,
    InputIterator2 first2,
    Type init,
    BinaryOperation1 binary_op1,
    BinaryOperation2 binary_op2);

template<class InputIterator, class Type, class BinaryOperation, class UnaryOperation>
Type transform_reduce(
    InputIterator first,
    InputIterator last,
    Type init,
    BinaryOperation binary_op,
    UnaryOperation unary_op);

template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class Type>
Type transform_reduce(
    ExecutionPolicy&& exec,
    ForwardIterator1 first1,
    ForwardIterator1 last1,
    ForwardIterator2 first2,
    Type init);

template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class Type, class BinaryOperation1, class BinaryOperation2>
Type transform_reduce(
    ExecutionPolicy&& exec,
    ForwardIterator1 first1,
    ForwardIterator1 last1,
    ForwardIterator2 first2,
    Type init,
    BinaryOperation1 binary_op1,
    BinaryOperation2 binary_op2);

template<class ExecutionPolicy, class ForwardIterator, class Type, class BinaryOperation, class UnaryOperation>
Type transform_reduce(
    ExecutionPolicy&& exec,
    ForwardIterator first,
    ForwardIterator last,
    Type init,
    BinaryOperation binary_op,
    UnaryOperation unary_op);

매개 변수

exec
실행 정책입니다.

first
범위의 첫 번째 요소를 binary_op 사용하여 합계를 합산하거나 결합하는 입력 반복기입니다.

first1
binary_op1 사용하여 합계를 합산하거나 결합할 범위의 첫 번째 요소에 주소를 지정하는 입력 반복기입니다.

last
범위의 마지막 요소를 합계로 처리하거나 binary_op 사용하여 결합하는 입력 반복기입니다. 이는 반복된 누적에 실제로 포함된 최종 요소 이외의 한 위치입니다.

last1
범위의 마지막 요소를 합계로 처리하거나 binary_op1 사용하여 결합하는 입력 반복기입니다. 이는 반복된 누적에 실제로 포함된 최종 요소 이외의 한 위치입니다.

result
첫 번째 요소에 대한 일련의 합계 또는 지정된 작업의 결과를 저장할 대상 범위의 주소를 지정하는 출력 반복기입니다.

init
binary_op 사용하여 각 요소가 차례로 추가되거나 결합되는 초기 값입니다.

binary_op
지정된 범위의 각 요소와 이전 애플리케이션의 결과에 적용할 이진 작업입니다.

unary_op
지정된 범위의 각 요소에 적용할 단항 연산입니다.

반환 값

변환된 다음 감소된 결과입니다.