Espaces de noms
Variantes
Affichages
Actions

std::swap_ranges

De cppreference.com
< cpp‎ | algorithm
 
 
Bibliothèque d'algorithmes
Fonctions
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Non-modification de la séquence des opérations
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.
Modification de la séquence des opérations
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.
Des opérations de partitionnement
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.
Opérations de tri (sur les gammes triés)
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.
is_sorted (C++11)
is_sorted_until (C++11)
sort
Opérations binaires de recherche (sur les gammes triés)
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.
Définir les opérations (sur les gammes triés)
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.
Opérations Heap
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 de fonctionnement
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.
Opérations numériques
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.
Bibliothèque C
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.
 
Déclaré dans l'en-tête <algorithm>
template< class ForwardIt1, class ForwardIt2 >
ForwardIt2 swap_ranges( ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2 )

Échange les éléments de l'intervalle [first1, last1) avec ceux de l'intervalle commençant à first2.

Sommaire

[modifier] Paramètres

first1, last1 - le premier intervalle d'éléments à échanger
first2 - début du second intervalle d'éléments à échanger
Type requirements
-
ForwardIt1, ForwardIt2 must meet the requirements of ForwardIterator.
-
The types of dereferenced ForwardIt1 and ForwardIt2 must meet the requirements of Swappable

[modifier] Retourne la valeur

Itérateur sur l'élément suivant le dernier élément échangé dans l'intervalle commençant à first2.

[modifier] Mise en œuvre possible

template<class ForwardIt1, class ForwardIt2>
ForwardIt1 swap_ranges(ForwardIt1 first1, 
                             ForwardIt1 last1, 
                             ForwardIt2 first2)
{
    while (first1 != last1) {
        std::iter_swap(first1++, first2++);
    }
    return first2;
}

[modifier] Exemple

Démontre l'échange de sous-intervalles de conteneurs différents

#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';
}

Résultat :

-1 -2 -3 4 5
1 2 3 -4 -5

[modifier] Complexité

linéaire en la distance entre first et last

[modifier] Voir aussi

permute les éléments pointés par deux itérateurs
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.

(fonction générique) [edit]
échange les valeurs de deux objets
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.

(fonction générique) [edit]