std::swap(std::any)
Von de.cppreference.net
| Definiert in Header <any>
|
||
void swap( any& lhs, any& rhs ) noexcept;
|
(seit C++17) | |
Überlädt den std::swap-Algorithmus für std::any. Vertauscht den Inhalt zweier any-Objekte durch Aufruf von lhs.swap(rhs).
Parameter
| lhs, rhs | - | zu vertauschende Objekte |
Beispiel
Diesen Code ausführen
#include <any> #include <print> #include <string> int main() { std::any p = 42, q = std::string{"Bishop"}; std::println("p: {}, q: {}", std::any_cast<int>(p), std::any_cast<std::string&>(q)); std::println("swap(p, q)"); std::swap(p, q); std::println("p: {}, q: {}", std::any_cast<std::string&>(p), std::any_cast<int>(q)); }
Ausgabe:
p: 42, q: Bishop swap(p, q) p: Bishop, q: 42
Siehe auch
tauscht zwei
any
Objekte
(öffentliche Elementfunktion) |