Namensräume
Varianten
Aktionen

std::transform

Aus cppreference.com
< cpp‎ | algorithm

 
 
Algorithm Bibliothek
Funktionen
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Nicht-modifizierende Sequenz Operationen
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.
Modifizierende Sequenz Operationen
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.
Partitionierungsoperationen
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.
Sortierung Operationen (auf sortierten Bereiche)
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.
Binary Suchaktionen (auf sortierten Bereiche)
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.
Set-Operationen (auf sortierten Bereiche)
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.
Heap-Operationen
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.
Minimum / Maximum Operationen
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.
Numerische Operationen
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-Bibliothek
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 gilt die angegebene Funktion auf einer Reihe und speichert das Ergebnis in einem anderen Bereich, beginnend bei 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.
In der ersten Version unäre Operation 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 .
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.

Inhaltsverzeichnis

[Bearbeiten] Parameter

first1, last1 -
die erste Reihe von Elementen zu transformieren
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 -
der Beginn des zweiten Bereichs von Elementen zu transformieren
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 -
der Beginn des Zielbereichs, kann gleich oder 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.

[Bearbeiten] Rückgabewert

Ausgabeiterator auf das Element nach dem letzten Element transformiert .
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.

[Bearbeiten] Komplexität

1)
genau std::distance(first1, last1) Anwendungen 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)
genau std::distance(first1, last1) Anwendungen 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.

[Bearbeiten] Anforderungen

unary_op und binary_op haben keine Nebenwirkungen. (bis C + +11)
Original:
unary_op and binary_op have no side effects. (bis 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_op und binary_op nicht entwerten keine Iteratoren, einschließlich der Ende Iteratoren oder zu modifizieren Elementen der Bereiche beteiligt. (seit 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. (seit C++11)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Die Absicht ist es, diesen Anforderungen parallel oder out-of-order Implementierungen std::transform ermöglichen. Um eine Funktion zu einer Sequenz in Ordnung anzuwenden, verwenden 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.

[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

Der folgende Code verwendet transformieren, um eine Zeichenfolge in Großbuchstaben mit dem toupper Funktion konvertieren:
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

[Bearbeiten] Siehe auch

gilt eine Funktion einer Reihe von Elementen
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.

(Funktions-Template) [edit]