std::string_view swap() method
- od C++17
// Non const version only
constexpr void swap( basic_string_view& v ) noexcept;
Exchanges the view with that of v
.
Parameters
v
- the view to exchange the contents with
Return value
(none)
Complexity
Constant - O(1).
Exceptions
(none)
Example
Main.cpp
#include <string_view>
#include <iostream>
int main() {
auto s1{ std::string_view{"⏺⏺⏺⏺⏺"} };
auto s2{ std::string_view{"⏹⏹⏹⏹⏹"} };
std::cout << "Before : " << s1 << ' ' << s2 << "\n";
s1.swap(s2);
std::cout << "After : " << s1 << ' ' << s2 << "\n";
}
Output
Before : ⏺⏺⏺⏺⏺ ⏹⏹⏹⏹⏹
After : ⏹⏹⏹⏹⏹ ⏺⏺⏺⏺⏺
This article originates from this CppReference page. It was likely altered for improvements or editors' preference. Click "Edit this page" to see all changes made to this document.
Hover to see the original license.
Hover to see the original license.