<QtSwap>

두 변수의 값을 바꾸기. 더 보기...

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()에 해당하는 Qt 버전이며, 다음 코드와 동일합니다.

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 에 대해 아무것도 알 수 없는 상황에서, 전통적으로 위의 두 줄을 작성했을 법한 제네릭 코드에서 사용하십시오.

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.