std:: swap (std::basic_string)
|
Definiert im Header
<string>
|
||
|
template
<
class
CharT,
class
Traits,
class
Alloc
>
void
swap
(
std::
basic_string
<
CharT, Traits, Alloc
>
&
lhs,
|
(bis C++17) | |
|
template
<
class
CharT,
class
Traits,
class
Alloc
>
void
swap
(
std::
basic_string
<
CharT, Traits, Alloc
>
&
lhs,
|
(seit C++17)
(constexpr seit C++20) |
|
Spezialisiert den std::swap Algorithmus für std::basic_string . Tauscht die Inhalte von lhs und rhs .
Entspricht lhs. swap ( rhs ) .
Inhaltsverzeichnis |
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
#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) |