<QtSwap>
Trocar os valores de duas variáveis. Mais...
| Header: | #include <QtSwap> |
Funções
| void | qSwap(T &lhs, T &rhs) |
Documentação da função
[constexpr noexcept(...)] template <typename T> void qSwap(T &lhs, T &rhs)
Troca os valores das variáveis ` lhs ` e ` rhs`, levando em consideração as sobrecargas de ` swap() ` específicas para cada tipo.
Essa função é a versão do Qt de boost::swap()e é 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)Use esta função principalmente em código genérico, onde tradicionalmente você teria escrito as duas linhas acima, pois não sabe nada sobre ` T`.
Se você já sabe o que é ` T `, use uma das seguintes opções, em ordem de preferência:
lhs.swap(rhs);se tal troca de membros existirstd::swap(lhs, rhs);se não existir um `swap()` específico para o tipo
Consulte ` boost::swap() ` no boost.org para obter mais detalhes.
Consulte também `std::swap ` no cppreference.com e ` Swappable ` no cppreference.com.
Observação: Esta função é `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.