std::transform
![]() |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
definiert 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
gilt die angegebene Funktion auf einer Reihe und speichert das Ergebnis in einem anderen Bereich, beginnend bei 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
ist auf den Bereich von [first1, last1)
definierten angewendet. In der zweiten Version die binäre Operation binary_op
ist auf Paare von Elementen aus zwei Bereichen eingesetzt: ein durch [first1, last1)
und der andere Anfang an first2
definiert .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.
Inhaltsverzeichnis |
[Bearbeiten] Parameter
first1, last1 | - | der erste, zu transformierende Elementbereich |
first2 | - | der Beginn des zweiten, zu transformierenden Elementbereichs |
d_first | - | der Beginn des Zielbereichs, kann gleich first1 oder first2 sein
|
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 &. |
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 .
|
[Bearbeiten] Rückgabewert
You can help to correct and verify the translation. Click here for instructions.
[Bearbeiten] Komplexität
1)unary_op
unary_op
You can help to correct and verify the translation. Click here for instructions.
binary_op
binary_op
You can help to correct and verify the translation. Click here for instructions.
[Bearbeiten] Anforderungen
unary_op
und binary_op
haben keine Nebenwirkungen. (bis C + +11)unary_op
and binary_op
have no side effects. (bis C + +11)You can help to correct and verify the translation. Click here for instructions.
unary_op
und binary_op
nicht entwerten keine Iteratoren, einschließlich der Ende Iteratoren oder zu modifizieren Elementen der Bereiche beteiligt. (seit C++11)unary_op
and binary_op
do not invalidate any iterators, including the end iterators, or modify any elements of the ranges involved. (seit 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.
[Bearbeiten] Mögliche Implementierung
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; } |
[Bearbeiten] Beispiel
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
[Bearbeiten] Siehe auch
Wendet eine Funktion auf eine Reihe von Elementen an (Funktions-Template) |