<QtSwap>
Scambiare i valori di due variabili. Altro...
| Header: | #include <QtSwap> |
Funzioni
| void | qSwap(T &lhs, T &rhs) |
Documentazione delle funzioni
[constexpr noexcept(...)] template <typename T> void qSwap(T &lhs, T &rhs)
Scambia i valori delle variabili ` lhs ` e ` rhs`, tenendo conto dei sovraccarichi di ` swap() ` specifici per tipo.
Questa funzione è la versione Qt di boost::swap() ed è equivalente a
using std::swap; // bring std::swap into scope (for built-in types)
swap(lhs, rhs); // unqualified call (picks up type-specific overloads
// via Argument-Dependent Lookup, or falls back to std::swap)Utilizza questa funzione principalmente nel codice generico, dove tradizionalmente avresti scritto le due righe precedenti, poiché non sai nulla riguardo a ` T`.
Se si conosce già il valore di ` T `, utilizzare una delle seguenti opzioni, in ordine di preferenza:
lhs.swap(rhs);se esiste un tale member-swapstd::swap(lhs, rhs);se non esiste un `swap()` specifico per il tipo
Per ulteriori dettagli, consulta la voce «boost::swap() » su boost.org.
Vedi anche std::swap su cppreference.com, Swappable su cppreference.com.
Nota: questa funzione è noexcept quando std::is_nothrow_swappable_v<T> è true.
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.