std::basic_string_view<CharT,Traits>::swap
From cppreference.com
< cpp | string | basic string view
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
std::basic_string_view
(C++20)
(C++20)
(C++23)
basic_string_view::swap
Constants
(until C++20)(until C++20)(until C++20)(until C++20)(until C++20)(C++20)
Deduction guides (C++20)
constexpr void swap( basic_string_view& v ) noexcept;
(since C++17)
Exchanges the view with that of v.
[edit] Parameters
v
-
view to swap with
[edit] Return value
(none)
[edit] Complexity
Constant.
[edit] 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