std::swap

std::swap (std::basic_stringbuf 특수화)

std::swap 알고리즘을 std::basic_stringbuf에 대해 오버로드한 함수예요. 두 문자열 버퍼의 상태를 서로 바꿔요. C++11부터 있어요.

출처: cppreference

본문

<sstream> 헤더에 정의돼 있고, std::basic_stringbufswap 오버로드예요.

template< class CharT, class Traits, class Alloc >
void swap( std::basic_stringbuf<CharT,Traits,Alloc>& lhs,
           std::basic_stringbuf<CharT,Traits,Alloc>& rhs );        // (until C++20)

template< class CharT, class Traits, class Alloc >
void swap( std::basic_stringbuf<CharT,Traits,Alloc>& lhs,
           std::basic_stringbuf<CharT,Traits,Alloc>& rhs )
    noexcept(noexcept(lhs.swap(rhs)));                              // (since C++20)

lhs의 상태를 rhs의 상태와 교환해요. 내부적으로 lhs.swap(rhs)를 호출해요. C++20부터는 noexcept(noexcept(lhs.swap(rhs)))로 예외 지정돼요.

  • 매개변수 lhs, rhs: 상태를 바꿀 std::basic_stringbuf 객체들.
  • 반환 값: 없음.

std::basic_stringbufstd::string을 스트림 버퍼로 다루는 클래스예요. 이 swap 오버로드 덕분에 일반화된 코드에서도 두 버퍼의 상태를 쉽게 교환할 수 있어요. 예제 섹션은 아직 미완성으로 표시돼 있어요.

더 알아보기 (Learn more)

cppreference