std::basic_string_view<CharT,Traits>::swap
来自cppreference.com
<tbody>
</tbody>
constexpr void swap( basic_string_view& v ) noexcept; |
(C++17 起) | |
交换视图与 v 的内容。
参数
| v | - | 要与之交换的视图 |
返回值
(无)
复杂度
常数。
示例
运行此代码
#include <iostream>
#include <string_view>
int main()
{
std::string_view a = "AAA";
std::string_view b = "BBBB";
std::cout << "交换前:\n"
"a = " << a << "\n"
"b = " << b << "\n\n";
a.swap(b);
std::cout << "交换后:\n"
"a = " << a << "\n"
"b = " << b << '\n';
}
输出:
交换前:
a = AAA
b = BBBB
交换后:
a = BBBB
b = AAA
参阅
| 交换两个对象的值 (函数模板) | |
| 交换两个范围的元素 (函数模板) | |
| 交换内容 ( std::basic_string<CharT,Traits,Allocator> 的公开成员函数)
|