swap (std::move_only_function)
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Old binders and adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
friend
void
swap
(
std::
move_only_function
&
lhs,
std::
move_only_function
&
rhs
)
noexcept
;
|
(seit C++23) | |
Überlädt den std::swap -Algorithmus für std::move_only_function . Tauscht den Zustand von lhs mit dem von rhs aus. Ruft effektiv lhs. swap ( rhs ) auf.
Diese Funktion ist für gewöhnliches
unqualified
oder
qualified lookup
nicht sichtbar und kann nur durch
argument-dependent lookup
gefunden werden, wenn
std::move_only_function<FunctionType>
eine assoziierte Klasse der Argumente ist.
Inhaltsverzeichnis |
Parameter
| lhs, rhs | - |
std::move_only_function
Objekte, deren Zustände ausgetauscht werden sollen
|
Rückgabewert
(keine)
Beispiel
#include <concepts> #include <functional> #include <iostream> void foo(const char* str, int x) { std::cout << "foo(\"" << str << "\", " << x << ")\n"; } void bar(const char* str, int x) { std::cout << "bar(\"" << str << "\", " << x << ")\n"; } int main() { std::move_only_function<void(const char*, int) const> f1{foo}; std::move_only_function<void(const char*, int) const> f2{bar}; f1("f1", 1); f2("f2", 2); std::cout << "std::ranges::swap(f1, f2);\n"; std::ranges::swap(f1, f2); // findet den hidden friend f1("f1", 1); f2("f2", 2); }
Ausgabe:
foo("f1", 1)
bar("f2", 2)
std::ranges::swap(f1, f2);
bar("f1", 1)
foo("f2", 2)
Siehe auch
tauscht die Ziele zweier
std::move_only_function
-Objekte
(öffentliche Elementfunktion) |
|
|
(C++11)
|
spezialisiert den
std::swap
-Algorithmus
(Funktionstemplate) |