次の方法で共有


<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 を使用して、合計または結合される範囲内の最後の要素、つまり反復処理され累積に実際に含まれる最後の要素の 1 つ次の位置を示す入力反復子。

init
binary_op を使用して、各要素がさらに追加または結合される初期値。

binary_op
指定された範囲と、以前の適用の結果の各要素に適用される二項演算。

戻り値

1 番目のテンプレート関数については、init と指定された範囲内のすべての要素の合計、または、2 番目のテンプレート関数の場合は、合計演算ではなく指定された binary_op を (*PartialResult, in_iter) に適用した結果 (この場合、PartialResult は演算の前の適用の結果、in_iter は範囲内の次の要素を指す反復子)。

解説

初期値は、範囲が空の場合に適切に定義された結果が存在すること、その場合に init が返されることを保証します。 二項演算は結合的または可換的である必要はありません。 結果は初期値 init に初期化され、次に、result = binary_op(result, in_iter) が範囲全体で反復的に計算されます。この場合、in_iter は、範囲内の連続した各要素を指す反復子です。 範囲が有効であることが必要で、複雑さは範囲のサイズに応じて線形的です。 2 項演算子の戻り値の型は、反復中のクロージャを確実にするために、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 値が計算されるように、出力反復子 result は入力反復子 first と同じ反復子にすることができます。

入力範囲に a1、a2、a3 の値のシーケンスがある場合、最初のテンプレート関数は連続する adjacent_differencea1、a2 - a1、a3 - a2 をターゲット範囲に格納します。

入力範囲に a1、a2、a3 の値のシーケンスがある場合、2 番目のテンプレート関数は連続する adjacent_differencea1、a2 binary_opa1、a3 binary_opa2 をターゲット範囲に格納します。

適用される演算の順序は指定されるため、二項演算 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<>() または指定された 2 項演算子を使用することによって、除外プレフィックス合計演算を計算します。 指定したターゲットから始まる範囲に結果を書き込みます。 "除外プレフィックス" 合計は、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 を使用して、合計または結合される範囲内の最後の要素、つまり反復処理され累積に実際に含まれる最後の要素の 1 つ次の位置を示す入力反復子。

result
一連の和または指定された演算の結果が格納されるターゲット範囲の先頭の要素を示す出力反復子。

init
binary_op を使用して、各要素がさらに追加または結合される初期値。

binary_op
指定された範囲と、以前の適用の結果の各要素に適用される二項演算。

戻り値

ターゲット範囲の最後を示す出力反復子: result + (last - first)。

gcd

整数 m と n の最大公約数を計算します。

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

パラメーター

mn
整数型の値。

戻り値

mn の絶対値の最大公約数を返します。mn の両方がゼロの場合は 0 を返します。 m または n の絶対値を common_type_t<M,N> 型の値として表現できない場合、結果は未定義になります。

inclusive_scan

初期値を指定して、範囲に対して std::plus<>() または指定された 2 項演算子を使用して、包含プレフィックス合計演算を計算します。 指定したターゲットから始まる範囲に結果を書き込みます。 "包含プレフィックス" 合計は、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 を使用して、合計または結合される範囲内の最後の要素、つまり反復処理され累積に実際に含まれる最後の要素の 1 つ次の位置を示す入力反復子。

result
一連の和または指定された演算の結果が格納されるターゲット範囲の先頭の要素を示す出力反復子。

init
binary_op を使用して、各要素がさらに追加または結合される初期値。

binary_op
指定された範囲と、以前の適用の結果の各要素に適用される二項演算。

戻り値

ターゲット範囲の最後を示す出力反復子: result + (last - first)。

inner_product

2 つの範囲の要素ごとの積の合計を計算し、それを指定された初期値に加算するか、または和や積の二項演算が指定された別の二項演算に置き換えられた汎用化されたプロシージャの結果を計算します。

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
2 番目の範囲との内積または一般化された内積を計算する必要がある、1 番目の範囲内の先頭の要素を示す入力反復子。

last1
2 番目の範囲との内積または一般化された内積を計算する必要がある、1 番目の範囲内の最後の要素を示す入力反復子。

first2
1 番目の範囲との内積または一般化された内積を計算する必要がある、2 番目の範囲内の先頭の要素を示す入力反復子。

init
範囲間の内積または一般化された内積を追加する必要がある初期値。

binary_op1
内積の一般化における要素ごとの内積に適用される内積の合計演算を置き換える二項演算。

binary_op2
内積の一般化における内積の要素ごとの乗算演算を置き換える二項演算。

戻り値

1 番目のメンバー関数は、要素ごとの積の合計を返し、それを指定された初期値に追加します。 したがって、ai と bi の値の範囲の場合、次を返します。

init + (a1 * b1) + (a2 * b2) + ... + (an * bn)

反復的に、initinit + (ai * bi) に置き換えます。

2 番目のメンバー関数は次を返します。

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

反復的に initinitbinary_op1 (ai binary_op2bi) に置き換えます。

解説

初期値は、範囲が空の場合に適切に定義された結果が存在することを保証します。 その場合、init が返されます。 二項演算は結合的または可換的である必要はありません。 範囲が有効であることが必要で、複雑さは範囲のサイズに応じて線形的です。 2 項演算子の戻り値の型は、反復中のクロージャを確実にするために、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

開始値を格納し、先頭の要素から始めて、その値の一連のインクリメント (value++) を [first, last) の間隔内の各要素に入力します。

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

パラメーター

first
入力する必要がある、範囲内の先頭の要素を示す入力反復子。

last
入力する必要がある、範囲内の最後の要素を示す入力反復子。

value
先頭の要素に格納し、以降の要素に関して連続してインクリメントするための開始値。

次の例は、iota 関数のいくつかの使用法を示しています。整数の list を入力し、次に、vectorlist を入力することで、random_shuffle 関数を使用できます。

// 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
指定された二項演算に従って、部分的に合計または結合される範囲内の最後の要素、つまり反復処理され累積に実際に含まれる最後の要素の 1 つ次の位置を示す入力反復子。

result
一連の部分和または指定された二項演算の連続する結果を格納するターゲット範囲の先頭の要素を示す出力反復子。

binary_op
部分和プロシージャの合計演算を置き換える一般的な演算で適用される二項演算。

戻り値

ターゲット範囲の最後を示す出力反復子: result + (last - first)。

解説

部分和が計算されるように、出力反復子 result は入力反復子 first と同じ反復子にすることができます。

入力範囲に a1、a2、... ax の値のシーケンスがある場合、最初のテンプレート関数は連続する部分和をターゲット範囲に格納します。 n 番目の要素は (a1 + a2 + a3 + ... + an) によって得られます。

入力範囲に a1、a2、a3 の値のシーケンスがある場合、2 番目のテンプレート関数は連続する部分和をターゲット範囲に格納します。 n 番目の要素は ((...((a1 binary_opa2) binary_opa3) binary_op ... ) binary_opan) によって得られます。

適用される演算の順序は指定されるため、二項演算 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 を使用して、合計または結合される範囲内の最後の要素、つまり反復処理され累積に実際に含まれる最後の要素の 1 つ次の位置を示す入力反復子。

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{} と同じです。

解説

binary_op が結合的かつ可換的でない限り、reduce の動作は非決定的です。 binary_op によって要素が変更されたり、[first, last] (両端を含む) の間隔のあらゆる反復子が無効になったりすると、この動作は未定義になります。

transform_exclusive_scan

指定した単項演算子を使用して範囲の要素を変換し、初期値を指定して、範囲に対して std::plus<>() または指定した 2 項演算子を使用することによって、除外プレフィックス合計演算を実行します。 指定したターゲットから始まる範囲に結果を書き込みます。 "除外プレフィックス" 合計は、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 を使用して、合計または結合される範囲内の最後の要素、つまり反復処理され累積に実際に含まれる最後の要素の 1 つ次の位置を示す入力反復子。

result
一連の和または指定された演算の結果が格納されるターゲット範囲の先頭の要素を示す出力反復子。

init
binary_op を使用して、各要素がさらに追加または結合される初期値。

binary_op
指定された範囲と、以前の適用の結果の各要素に適用される二項演算。

unary_op
指定した範囲内の各要素に適用する単項演算。

transform_inclusive_scan

指定した単項演算子を使用して範囲の要素を変換し、初期値を指定して、範囲に対して std::plus<>() または指定した 2 項演算子を使用することによって、包含プレフィックス合計演算を実行します。 指定したターゲットから始まる範囲に結果を書き込みます。 "包含プレフィックス" 合計は、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 を使用して、合計または結合される範囲内の最後の要素、つまり反復処理され累積に実際に含まれる最後の要素の 1 つ次の位置を示す入力反復子。

result
一連の和または指定された演算の結果が格納されるターゲット範囲の先頭の要素を示す出力反復子。

binary_op
指定された範囲と、以前の適用の結果の各要素に適用される二項演算。

unary_op
指定した範囲内の各要素に適用する単項演算。

init
binary_op を使用して、各要素がさらに追加または結合される初期値。

transform_reduce

要素の範囲を変換し、変換された要素を任意の順序で減算するファンクターを適用します。 実質的には、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 を使用して、合計または結合される範囲内の最後の要素、つまり反復処理され累積に実際に含まれる最後の要素の 1 つ次の位置を示す入力反復子。

last1
binary_op1 を使用して、合計または結合される範囲内の最後の要素、つまり反復処理され累積に実際に含まれる最後の要素の 1 つ次の位置を示す入力反復子。

result
一連の和または指定された演算の結果が格納されるターゲット範囲の先頭の要素を示す出力反復子。

init
binary_op を使用して、各要素がさらに追加または結合される初期値。

binary_op
指定された範囲と、以前の適用の結果の各要素に適用される二項演算。

unary_op
指定した範囲内の各要素に適用する単項演算。

戻り値

変換されてから減算された結果。