std::swap(std::basic_string)
Aus de.cppreference.net
| Definiert in Header <string>
|
||
template< class CharT, class Traits, class Alloc >
void swap( std::basic_string<CharT, Traits, Alloc>& lhs,
std::basic_string<CharT, Traits, Alloc>& rhs );
|
(bis C++17) | |
template< class CharT, class Traits, class Alloc >
void swap( std::basic_string<CharT, Traits, Alloc>& lhs,
std::basic_string<CharT, Traits, Alloc>& rhs ) noexcept(/* see below */);
|
(seit C++17) (constexpr seit C++20) |
|
Spezialisiert den Algorithmus std::swap für std::basic_string. Tauscht die Inhalte von lhs und rhs aus.
Äquivalent zu lhs.swap(rhs).
Parameter
| lhs, rhs | - | Zeichenketten, deren Inhalte ausgetauscht werden sollen |
Rückgabewert
(keine)
Komplexität
Konstante.
Exceptions
noexcept
Spezifikation:
noexcept
(
noexcept
(
lhs.
swap
(
rhs
)
)
)
|
(seit C++17) |
Beispiel
Diesen Code ausführen
#include <iostream> #include <string> int main() { std::string a = "AAA"; std::string b = "BBBB"; std::cout << "Before swap:\n" "a = " << a << "\n" "b = " << b << "\n\n"; std::swap(a, b); std::cout << "After swap:\n" "a = " << a << "\n" "b = " << b << '\n'; }
Ausgabe:
Before swap: a = AAA b = BBBB After swap: a = BBBB b = AAA
Fehlerberichte
Die folgenden verhaltensändernden Fehlerberichte wurden rückwirkend auf zuvor veröffentlichte C++-Standards angewendet.
| DR | Angewendet auf | Verhalten wie veröffentlicht | Korrigiertes Verhalten |
|---|---|---|---|
| LWG 2064 | C++11 |
non-member
swap
war noexcept und inkonsistent mit member
swap
|
noexcept entfernt |
Siehe auch
|
tauscht die Inhalte aus
(öffentliche Elementfunktion) |