C++ 参考手册

定义于头文件 <string>
template< class CharT, class Traits, class Alloc >

void swap( std::basic_string<CharT, Traits, Alloc> &lhs,

           std::basic_string<CharT, Traits, Alloc> &rhs );
(C++17 前)
template< class CharT, class Traits, class Alloc >

void swap( std::basic_string<CharT, Traits, Alloc> &lhs,

           std::basic_string<CharT, Traits, Alloc> &rhs ) noexcept(/* see below */);
(C++17 èµ·)
(C++20 前)
template< class CharT, class Traits, class Alloc >

constexpr void
    swap( std::basic_string<CharT, Traits, Alloc> &lhs,

          std::basic_string<CharT, Traits, Alloc> &rhs ) noexcept(/* see below */);
(C++20 èµ·)

为 std::basic_string 特化 std::swap 算法。交换 lhs 与 rhs 的内容。等价于 lhs.swap(rhs) 。

参数

lhs, rhs - 要交换内容的 string

返回值

(无)

复杂度

常数。

异常

noexcept 规定:  
noexcept(noexcept(lhs.swap(rhs)))
(C++17 èµ·)

参阅

交换内容
(公开成员函数)