std::transform
|
|
このページは、Google 翻訳を使って英語版から機械翻訳されました。
翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
| Defined in header <algorithm>
|
||
| template< class InputIt, class OutputIt, class UnaryOperation > OutputIt transform( InputIt first1, InputIt last1, OutputIt d_first, |
(1) | |
| template< class InputIt1, class InputIt2, class OutputIt, class BinaryOperation > OutputIt transform( InputIt1 first1, InputIt1 last1, InputIt2 first2, |
(2) | |
std::transform範囲に指定した関数を適用し、d_firstから始まる別の範囲に結果を格納. std::transform applies the given function to a range and stores the result in another range, beginning at d_first. You can help to correct and verify the translation. Click here for instructions.
unary_opは[first1, last1)によって定義された範囲に適用されます。第二版ではバイナリ操作binary_opは二つの範囲の要素のペアに適用されます。[first1, last1)でfirst2や他の初めによって定義された1.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.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 &. |
| 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 &. |
| 型の要件 | ||
-InputIt は InputIterator
の要求を満足しなければなりません。 | ||
-InputIt1 は InputIterator
の要求を満足しなければなりません。 | ||
-InputIt2 は InputIterator
の要求を満足しなければなりません。 | ||
-OutputIt は OutputIterator
の要求を満足しなければなりません。 | ||
[編集] 値を返します
You can help to correct and verify the translation. Click here for instructions.
[編集] 複雑性
1)unary_opアプリケーションunary_opYou can help to correct and verify the translation. Click here for instructions.
binary_opアプリケーションbinary_opYou can help to correct and verify the translation. Click here for instructions.
[編集] 要件
unary_opとbinary_op全く副作用がありません。 (C++11以前)unary_op and binary_op have no side effects. (C++11以前)You can help to correct and verify the translation. Click here for instructions.
unary_opとbinary_op終了イテレータを含む任意のイテレータを無効、または関与の範囲の任意の要素を変更しません。 (C++11およびそれ以降)unary_op and binary_op do not invalidate any iterators, including the end iterators, or modify any elements of the ranges involved. (C++11およびそれ以降)You can help to correct and verify the translation. Click here for instructions.
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; } |
[編集] 例
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; }
出力:
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. (関数テンプレート) | |