From cppreference.com
constexprvoidswap(basic_string_view&v)noexcept;(since C++17)Exchanges the view with that of v.
Parameters
v - view to swap with Complexity
Constant.
Example
Run this code
#include<iostream>#include<string_view>intmain(){std::string_viewa="AAA";std::string_viewb="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
swaps the values of two objects
(function template)
swaps two ranges of elements
(function template & algorithm function object)
(C++20)
swaps the contents
(public member function of std::basic_string<CharT,Traits,Allocator>)