std:: swap (std::any)
From cppreference.net
C++
Utilities library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Défini dans l'en-tête
<any>
|
||
|
void
swap
(
any
&
lhs, any
&
rhs
)
noexcept
;
|
(depuis C++17) | |
Surcharge l'algorithme
std::swap
pour
std::any
. Échange le contenu de deux objets
any
en appelant
lhs.
swap
(
rhs
)
.
Paramètres
| lhs, rhs | - | objets à échanger |
Exemple
Exécuter ce code
#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)); }
Sortie :
p: 42, q: Bishop swap(p, q) p: Bishop, q: 42
Voir aussi
échange deux
any
objets
(fonction membre publique) |