std::swap_ranges
Aus cppreference.com
![]() | 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. |
Defined in header <algorithm> | ||
template<class ForwardIt1, class ForwardIt2 > ForwardIt2 swap_ranges( ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2 ) | ||
Exchanges Elemente zwischen Reichweite
[first1, last1)
und einem anderen Bereich ab first2
. Original:
Exchanges elements between range
[first1, last1)
and another range starting at first2
. The text has been machine-translated via Google Translate.
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.
Inhaltsverzeichnis |
[Bearbeiten]Parameter
first1, last1 | - | die erste Reihe von Elementen zu tauschen Original: the first range of elements to swap The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
first2 | - | Beginn der zweiten Reihe von Elementen zu tauschen Original: beginning of the second range of elements to swap The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Type requirements | ||
-ForwardIt1, ForwardIt2 must meet the requirements of ForwardIterator . | ||
-The types of dereferenced ForwardIt1 and ForwardIt2 must meet the requirements of Swappable |
[Bearbeiten]Rückgabewert
Iterator das Element nach dem letzten Element in dem Bereich beginnend mit
first2
ausgetauscht .Original:
Iterator to the element past the last element exchanged in the range beginning with
first2
.The text has been machine-translated via Google Translate.
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
template<class ForwardIt1, class ForwardIt2> ForwardIt1 swap_ranges(ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2){while(first1 != last1){std::iter_swap(first1++, first2++);}return first2;} |
[Bearbeiten]Beispiel
Veranschaulicht Auslagern von Teilbereichen aus verschiedenen Behältern
Original:
Demonstrates swapping of subranges from different containers
The text has been machine-translated via Google Translate.
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.
#include <algorithm>#include <list>#include <vector>#include <iostream>int main(){std::vector<int> v ={1, 2, 3, 4, 5};std::list<int> l ={-1, -2, -3, -4, -5}; std::swap_ranges(v.begin(), v.begin()+3, l.begin()); for(int n : v)std::cout<< n <<' ';std::cout<<'\n';for(int n : l)std::cout<< n <<' ';std::cout<<'\n';}
Output:
-1 -2 -3 4 5 1 2 3 -4 -5
[Bearbeiten]Komplexität
linear im Abstand
first
und last
Original:
linear in the distance between
first
and last
The text has been machine-translated via Google Translate.
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]Siehe auch
Swaps die Elemente, auf die zwei Iteratoren Original: swaps the elements pointed to by two iterators The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (Funktions-Template) | |
tauscht die Werte von zwei Objekten Original: swaps the values of two objects The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (Funktions-Template) |