<QtSwap>
2つの変数の値を交換する。詳細...
| Header: | #include <QtSwap> |
関数
| void | qSwap(T &lhs, T &rhs) |
関数のドキュメント
[constexpr noexcept(...)] template <typename T> void qSwap(T &lhs, T &rhs)
変数lhs とrhs の値を、型固有のswap() のオーバーロードを考慮して入れ替えます。
この関数は、Qt 版 boost::swap()に相当し、以下と同等です。
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)この関数は、主に汎用コード内で使用してください。汎用コードでは、T について何も分からないため、従来なら上記の2行を記述していたような場面で役立ちます。
T が何であるかがすでに分かっている場合は、優先順位の高い順に以下のいずれかのオプションを使用してください:
lhs.swap(rhs);そのようなメンバースワップが存在する場合std::swap(lhs, rhs);型固有のswap()が存在しない場合
詳細については、boost.orgの「boost::swap() 」を参照してください。
cppreference .com の「std::swap 」および「Swappable 」も参照してください。
注: std::is_nothrow_swappable_v<T> がtrue の場合、この関数は noexcept です。
© 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.