table of contents
- Tumbleweed 2026.11.13-1.1
- Leap-16.0
- Leap-15.6
| std::basic_string_view::swap(3) | C++ Standard Libary | std::basic_string_view::swap(3) |
NAME¶
std::basic_string_view::swap - std::basic_string_view::swap
Synopsis¶
constexpr void swap( basic_string_view& v ) noexcept; (since C++17)
Exchanges the view with that of v.
Parameters¶
v - view to swap with
Return value¶
(none)
Complexity¶
Constant.
Example¶
// Run this code
#include <iostream> #include <string_view>
int main() {
std::string_view a = "AAA";
std::string_view b = "BBBB";
std::cout << "Before swap:\n"
"a = " << a << "\n"
"b = " << b << "\n\n";
a.swap(b);
std::cout << "After swap:\n"
"a = " << a << "\n"
"b = " << b << '\n'; }
Output:¶
Before swap: a = AAA b = BBBB
After swap: a = BBBB b = AAA
See also¶
swap swaps the values of two objects
(function template) swap_ranges swaps two ranges of elements
(function template) swap swaps the contents
(public member function of
std::basic_string<CharT,Traits,Allocator>)
| 2026.11.10 | http://cppreference.com |