名前空間
変種
操作

std::transform

提供: cppreference.com
< cpp‎ | algorithm

 
 
アルゴリズムライブラリ
機能します
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
シーケンス動作を非改変
Original:
Non-modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
シーケンス動作を変更する
Original:
Modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
操作を仕切る
Original:
Partitioning operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(ソートされた範囲で)ソート操作
Original:
Sorting operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
バイナリ検索操作(ソート範囲で)
Original:
Binary search operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(ソートされた範囲で)操作を設定します
Original:
Set operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ヒープ操作
Original:
Heap operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
最小値/最大値操作
Original:
Minimum/maximum operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
数値演算
Original:
Numeric operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Cライブラリ
Original:
C library
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
Defined in header <algorithm>
template< class InputIt, class OutputIt, class UnaryOperation >

OutputIt transform( InputIt first1, InputIt last1, OutputIt d_first,

                    UnaryOperation unary_op );
(1)
template< class InputIt1, class InputIt2, class OutputIt, class BinaryOperation >

OutputIt transform( InputIt1 first1, InputIt1 last1, InputIt2 first2,

                    OutputIt d_first, BinaryOperation binary_op );
(2)
std::transform範囲に指定した関数を適用し、d_firstから始まる別の範囲に結果を格納.
Original:
std::transform applies the given function to a range and stores the result in another range, beginning at d_first.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
最初のバージョンでは単項演算unary_op[first1, last1)によって定義された範囲に適用されます。第二版ではバイナリ操作binary_opは二つの範囲の要素のペアに適用されます。[first1, last1)first2や他の初めによって定義された1.
Original:
In the first version unary operation unary_op is applied to the range defined by [first1, last1). In the second version the binary operation binary_op is applied to pairs of elements from two ranges: one defined by [first1, last1) and the other beginning at first2.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目次

[編集] パラメータ

first1, last1 -
変換する要素の最初の範囲
Original:
the first range of elements to transform
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
first2 -
変換する要素の第2の範囲の始まり
Original:
the beginning of the second range of elements to transform
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
d_first -
目的の範囲の始まりは、first1またはfirst2に等しいかもしれません
Original:
the beginning of the destination range, may be equal to first1 or first2
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
unary_op - unary operation function object that will be applied.

The signature of the function should be equivalent to the following:

 Ret fun(const Type &a);

The signature does not need to have const &.
The type  Type must be such that an object of type InputIt can be dereferenced and then implicitly converted to  Type. The type  Ret must be such that an object of type OutputIt can be dereferenced and assigned a value of type  Ret. ​

binary_op - binary operation function object that will be applied.

The signature of the function should be equivalent to the following:

 Ret fun(const Type1 &a, const Type2 &b);

The signature does not need to have const &.
The types  Type1 and  Type2 must be such that objects of types InputIt1 and InputIt2 can be dereferenced and then implicitly converted to  Type1 and  Type2 respectively. The type  Ret must be such that an object of type OutputIt can be dereferenced and assigned a value of type  Ret. ​

Type requirements
-
InputIt must meet the requirements of InputIterator.
-
InputIt1 must meet the requirements of InputIterator.
-
InputIt2 must meet the requirements of InputIterator.
-
OutputIt must meet the requirements of OutputIterator.

[編集] 値を返します

最後の要素は、過去の要素への出力イテレータは、形質転換された.
Original:
output iterator to the element past the last element transformed.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 複雑

1)
std::distance(first1, last1)の正確unary_opアプリケーション
Original:
exactly std::distance(first1, last1) applications of unary_op
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
std::distance(first1, last1)の正確binary_opアプリケーション
Original:
exactly std::distance(first1, last1) applications of binary_op
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 要件

unary_opbinary_op全く副作用がありません。 (C + + 11時まで)
Original:
unary_op and binary_op have no side effects. (C + + 11時まで)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
unary_opbinary_op終了イテレータを含む任意のイテレータを無効、または関与の範囲の任意の要素を変更しません。 (C + + 11以来)
Original:
unary_op and binary_op do not invalidate any iterators, including the end iterators, or modify any elements of the ranges involved. (C + + 11以来)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
これらの要件の目的は、並列またはstd::transformのアウトオブオーダーの実装を可能にすることである。順序でシーケンスに関数を適用するには、std::for_eachを使用.
Original:
The intent of these requirements is to allow parallel or out-of-order implementations of std::transform. To apply a function to a sequence in-order, use std::for_each.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 可能な実装

First version
template<class InputIt, class OutputIt, class UnaryOperation>
OutputIt transform(InputIt first1, InputIt last1, OutputIt d_first, 
                   UnaryOperation unary_op)
{
    while (first1 != last1) {
        *d_first++ = unary_op(*first1++);
    }
    return d_first;
}
Second version
template<class InputIt1, class InputIt2, 
         class OutputIt, class BinaryOperation>
OutputIt transform(InputIt first1, InputIt last1, InputIt first2, 
                   OutputIt d_first, BinaryOperation binary_op)
{
    while (first1 != last1) {
        *d_first++ = binary_op(*first1++, *first2++);
    }
    return d_first;
}

[編集]

次のコードは、toupperは関数を使って文字列を大文字に変換するために変換を使用しています
Original:
The following code uses transform to convert a string to uppercase using the toupper function:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <string>
#include <cctype>
#include <algorithm>
#include <iostream>
 
int main()
{
    std::string s("hello");
    std::transform(s.begin(), s.end(), s.begin(), (int (*)(int))std::toupper);
    std::cout << s;
 }

Output:

HELLO

[編集] も参照してください

ある範囲の要素に関数が適用されます
Original:
applies a function to a range of elements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート) [edit]