<QtSwap>
Intercambiar los valores de dos variables. Más...
| Header: | #include <QtSwap> |
Funciones
| void | qSwap(T &lhs, T &rhs) |
Documentación de la función
[constexpr noexcept(...)] template <typename T> void qSwap(T &lhs, T &rhs)
Intercambia los valores de las variables ` lhs ` y ` rhs`, teniendo en cuenta las sobrecargas de ` swap() ` específicas de cada tipo.
Esta función es la versión de Qt de boost::swap(), y es 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)Utiliza esta función principalmente en código genérico, donde tradicionalmente habrías escrito las dos líneas anteriores, ya que no sabes nada sobre ` T`.
Si ya sabes qué es T, utiliza una de las siguientes opciones, por orden de preferencia:
lhs.swap(rhs);si existe dicho intercambio de miembrosstd::swap(lhs, rhs);si no existe un `swap()` específico para el tipo
Consulta «boost::swap() » en boost.org para obtener más detalles.
Consulta también «std::swap » en cppreference.com y «Swappable » en cppreference.com.
Nota: Esta función es «noexcept» cuando std::is_nothrow_swappable_v<T> es 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.