weak_ptr_swap2

weak_ptr_swap2 (weak_ptr swap 비멤버)

<memory> 헤더에 정의되어 있어요. std::weak_ptr에 대한 std::swap 알고리즘 특수화예요. lhsrhs의 내용을 맞바꿔요. lhs.swap(rhs)를 호출해요. C++11부터 도입됐어요.

출처: cppreference

본문

template< class T >
void swap( std::weak_ptr<T>& lhs, std::weak_ptr<T>& rhs ) noexcept;

(C++11부터, constexpr since C++26)

std::weak_ptr에 대한 std::swap 알고리즘을 특수화해요. lhsrhs의 내용을 맞바꿔요. lhs.swap(rhs)를 호출해요.

매개변수

  • lhs, rhs: 내용을 맞바꿀 스마트 포인터

복잡도

상수(constant).

std::shared_ptr<int> sp = std::make_shared<int>(10);
std::weak_ptr<int> a = sp;
std::weak_ptr<int> b;
std::swap(a, b);   // a 는 empty, b 는 sp 를 참조

더 알아보기 (Learn more)

cppreference