<QtSwap>

Intercambiar los valores de dos variables. Más...

Header: #include <QtSwap>

Funciones

void qSwap(T &lhs, T &rhs)

Descripción detallada

Documentación de funciones

[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 específicas del tipo swap().

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)

Usa esta función principalmente en código genérico, donde tradicionalmente habrías escrito las dos líneas anteriores, porque no sabes nada sobre T.

Si ya sabe lo que es T, utilice una de las siguientes opciones, por orden de preferencia:

  • lhs.swap(rhs); si existe tal miembro-swap
  • std::swap(lhs, rhs); si no existe un tipo específico swap()

Véase boost::swap() en boost.org para más detalles.

Véase también std::swap en cppreference .com, 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.