Namensräume
Varianten
Aktionen

std::remove, std::remove_if

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 ForwardIt, class T >
ForwardIt remove( ForwardIt first, ForwardIt last, const T& value );
(1)
template< class ForwardIt, class UnaryPredicate >
ForwardIt remove_if( ForwardIt first, ForwardIt last, UnaryPredicate p );
(2)
Entfernt alle Elemente, die die spezifischen Kriterien aus dem Bereich [first, last). Die erste Version entfernt alle Elemente, die gleich value sind, entfernt der zweiten Version, für die alle Elemente Prädikats p kehrt true .
Original:
Removes all elements satisfying specific criteria from the range [first, last). The first version removes all elements that are equal to value, the second version removes all elements for which predicate p returns true.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Entfernen durch Verschieben der Elemente in dem Bereich derart, dass Elemente, die gelöscht werden überschrieben werden durchgeführt. Die Elemente zwischen den alten und den neuen Enden der Skala haben unbestimmte Werte. Ein Iterator zum neuen Ende des Bereichs zurückgegeben wird. Relative Reihenfolge der Elemente, die bleiben erhalten bleibt .
Original:
Removing is done by shifting the elements in the range in such a way that elements to be erased are overwritten. The elements between the old and the new ends of the range have unspecified values. An iterator to the new end of the range is returned. Relative order of the elements that remain is preserved.
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

first, last -
der Bereich der Elemente zu verarbeiten
Original:
the range of elements to process
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
value -
der Wert der Elemente zu entfernen
Original:
the value of elements to remove
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
p - unary predicate which returns ​true
wenn das Element entfernt werden sollte
Original:
if the element should be removed
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
.

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

 bool pred(const Type &a);

The signature does not need to have const &, but the function must not modify the objects passed to it.
The type Type must be such that an object of type ForwardIt can be dereferenced and then implicitly converted to Type. ​

Type requirements
-
ForwardIt must meet the requirements of ForwardIterator.
-
The type of dereferenced ForwardIt must meet the requirements of MoveAssignable.

[Bearbeiten] Rückgabewert

Iterator das neue Ende des Bereichs
Original:
Iterator to the new end of the range
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

Genau std::distance(first, last) Anwendungen des Prädikats .
Original:
Exactly std::distance(first, last) applications of the predicate.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[Bearbeiten] Notes

Die ähnlich benannten Behälter Elementfunktionen list::remove, list::remove_if, forward_list::remove und forward_list::remove_if löscht die entfernten Elemente .
Original:
The similarly-named container member functions list::remove, list::remove_if, forward_list::remove, and forward_list::remove_if erase the removed elements.
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 ForwardIt, class T>
ForwardIt remove(ForwardIt first, ForwardIt last, 
                       const T& value)
{
    ForwardIt result = first;
    for (; first != last; ++first) {
        if (!(*first == value)) {
            *result++ = *first;
        }
    }
    return result;
}
Second version
template<class ForwardIt, class UnaryPredicate>
ForwardIt remove_if(ForwardIt first, ForwardIt last, 
                          UnaryPredicate p)
{
    ForwardIt result = first;
    for (; first != last; ++first) {
        if (!p(*first)) {
            *result++ = *first;
        }
    }
    return result;
}

[Bearbeiten] Beispiel

Der folgende Code entfernt alle Leerzeichen aus einem String, indem sie bis zum Ende des Strings und dann Löschen .
Original:
The following code removes all spaces from a string by moving them to the end of the string and then erasing.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#include <algorithm>
#include <string>
#include <iostream>
int main()
{
    std::string str = "Text with some   spaces";
    str.erase(std::remove(str.begin(), str.end(), ' '),
              str.end());
    std::cout << str << '\n';
}

Output:

Textwithsomespaces

[Bearbeiten] Siehe auch

Kopiert einen Bereich von Elementen ohne die Seiten, die bestimmte Kriterien erfüllen
Original:
copies a range of elements omitting those that satisfy specific criteria
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]