<QtSwap>
Die Werte zweier Variablen vertauschen. Mehr...
| Header: | #include <QtSwap> |
Funktionen
| void | qSwap(T &lhs, T &rhs) |
Funktionsdokumentation
[constexpr noexcept(...)] template <typename T> void qSwap(T &lhs, T &rhs)
Tauscht die Werte der Variablen „ lhs “ und „ rhs “ unter Berücksichtigung typspezifischer Überladungen von „ swap() “ aus.
Diese Funktion ist die Qt-Version von boost::swap()und entspricht
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, in dem Sie traditionell die beiden oben genannten Zeilen geschrieben hätten, da Sie nichts über ` T` wissen.
Wenn Sie bereits wissen, was ` T ` ist, verwenden Sie eine der folgenden Optionen in der Reihenfolge ihrer Präferenz:
lhs.swap(rhs);falls ein solcher „member-swap“ existiertstd::swap(lhs, rhs);wenn kein typspezifisches `swap()` existiert
Weitere Details findest du unter „boost::swap() “ auf boost.org.
Siehe auch „std::swap “ auf cppreference.com sowie „Swappable “ auf cppreference.com.
Hinweis: Diese Funktion ist „noexcept“, wenn „ std::is_nothrow_swappable_v<T> “ „ true “ ist.
© 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.