◐ Shell
clean mode source ↗

std::swap — cppreference.com

<tbody> </tbody>

Déclaré dans l'en-tête

<algorithm>

Déclaré dans l'en-tête

<utility>

(avant C++11)
(depuis C++11)

template< class T > void swap( T& a, T& b );

(1)

template< class T2, size_t N > void swap( T2 (&a)[N], T2 (&b)[N]);

(2) (depuis C++11)

Échange les valeurs données.

1) Échanges les valeurs a et b.

2) Echange les tableaux a et b. Pour cela, appelle std::swap_ranges(a, a+N, b).

Paramètres

a, b - les valeurs à permuter
Type requirements
-T must meet the requirements of MoveAssignable and MoveConstructible.
-T2 must meet the requirements of Swappable.

Retourne la valeur

Aucune

Exceptions

1)

noexcept

specification:   (depuis C++11)

<tbody> </tbody>

noexcept(noexcept( std::is_nothrow_move_constructible<T>::value && std::is_nothrow_move_assignable<T>::value ))

2)

noexcept

specification:   (depuis C++11)

<tbody> </tbody>

noexcept(noexcept(swap(*a, *b)))

Complexité

1)

Constante

Original:

Constant

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

2)

Linéaire en N

Original:

Linear in N

The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Spécialisations

Il est autorisé à la fois de surcharger et de spécialiser l'algorithme std::swap, mais les surcharges sont généralement préférées car les spécialisations d'un modèle de fonction ne sont pas autorisées pour les classes template. Les fonctions de la bibliothèque standard utilisent toujours les surcharges fournies par l'utilisateur lors du swap, si elles sont reconnues lors de la recherche des argument (d'après le concept Swappable).

Les surcharges suivantes sont déjà fournies par la bibliothèque standard :

l'algorithme spécialisé std::swap

Original:

specializes the std::swap algorithm

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]

l'algorithme spécialisé std::swap

Original:

specializes the std::swap algorithm

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]

l'algorithme spécialisé std::swap

Original:

specializes the std::swap algorithm

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]

l'algorithme spécialisé std::swap

Original:

specializes the std::swap algorithm

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]

l'algorithme spécialisé std::swap

Original:

specializes the std::swap algorithm

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]
permet de spécialiser l'algorithme std::swap
(fonction générique) [edit]

l'algorithme spécialisé std::swap

Original:

specializes the std::swap algorithm

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]

l'algorithme spécialisé std::swap

Original:

specializes the std::swap algorithm

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]

l'algorithme spécialisé std::swap

Original:

specializes the std::swap algorithm

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]

l'algorithme spécialisé std::swap

Original:

specializes the std::swap algorithm

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]

l'algorithme spécialisé std::swap

Original:

specializes the std::swap algorithm

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]

l'algorithme spécialisé std::swap

Original:

specializes the std::swap algorithm

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]

l'algorithme spécialisé std::swap

Original:

specializes the std::swap algorithm

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]

l'algorithme spécialisé std::swap

Original:

specializes the std::swap algorithm

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]

l'algorithme spécialisé std::swap

Original:

specializes the std::swap algorithm

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]

l'algorithme spécialisé std::swap

Original:

specializes the std::swap algorithm

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]

l'algorithme spécialisé std::swap

Original:

specializes the std::swap algorithm

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]

l'algorithme spécialisé std::swap

Original:

specializes the std::swap algorithm

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]

l'algorithme spécialisé std::swap

Original:

specializes the std::swap algorithm

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]

l'algorithme spécialisé std::swap

Original:

specializes the std::swap algorithm

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]

l'algorithme spécialisé std::swap

Original:

specializes the std::swap algorithm

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]

l'algorithme spécialisé std::swap

Original:

specializes the std::swap algorithm

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]

l'algorithme spécialisé std::swap

Original:

specializes the std::swap algorithm

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]
spécialise l'algorithme std::swap()
(fonction générique)
spécialise l'algorithme std::swap()
(fonction générique)
spécialise l'algorithme std::swap()
(fonction générique)
spécialise l'algorithme std::swap()
(fonction générique)
spécialise l'algorithme std::swap()
(fonction générique)
spécialise l'algorithme std::swap()
(fonction générique)

l'algorithme spécialisé std::swap

Original:

specializes the std::swap algorithm

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]

l'algorithme spécialisé std::swap

Original:

specializes the std::swap algorithm

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]

l'algorithme spécialisé std::swap

Original:

specializes the std::swap algorithm

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]
spécialise l'algorithme std::swap()
(fonction générique)
spécialise l'algorithme std::swap()
(fonction générique)

l'algorithme spécialisé std::swap

Original:

specializes the std::swap algorithm

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]
spécialise l'algorithme std::swap()
(fonction générique)
spécialise l'algorithme std::swap()
(fonction générique)
spécialise l'algorithme std::swap()
(fonction générique)

Exemple

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]

swaps de deux gammes d'éléments

Original:

swaps two ranges of elements

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]