<QtSwap> Proxy-Seite

Funktionen

void qSwap(T &lhs, T &rhs)

Dokumentation der Funktionen

[constexpr noexcept(...)] template <typename T> void qSwap(T &lhs, T &rhs)

Tauscht die Werte der Variablen lhs und rhs aus, wobei typspezifische Überladungen von swap() berücksichtigt werden.

Diese Funktion ist Qt's Version von boost::swap()und ist äquivalent zu

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)

Verwenden Sie diese Funktion vor allem in generischem Code, wo Sie traditionell die obigen zwei Zeilen geschrieben hätten, weil Sie nichts über T wissen.

Wenn Sie bereits wissen, was T ist, dann verwenden Sie eine der folgenden Optionen, in der Reihenfolge Ihrer Präferenz:

  • lhs.swap(rhs); wenn ein solcher Member-Swap existiert
  • std::swap(lhs, rhs); wenn kein typspezifisches swap() existiert

Siehe boost::swap() auf boost.org für weitere Details.

Siehe auch std::swap auf cppreference.com, Swappable auf cppreference.com.

Hinweis: Diese Funktion ist noexcept, wenn std::is_nothrow_swappable_v<T> true ist.

© 2025 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.