std::basic_..._view::swap(3)
π NAME π
okay bestie, welcome to the std::basic_..._view::swap page from the C++ Standard Libary manual (yes, thatβs the manualβs spelling and weβre not fixing it π
). The NAME line is doing that iconic double-repeat thing: std::basic_string_view::swap β std::basic_string_view::swap. slay, we love a consistent queen β¨.
β¨ Synopsis β¨
constexpr void swap( basic_string_view& v ) noexcept;
and yes, itβs (since C++17) β been serving looks since then π«Ά.
It exchanges the view with that of v. Like, the views trade places. Thatβs the whole gig, no cap.
π Parameters π
vβ view to swap with. thatβs it, thatβs the parameter π
πΈ Return value πΈ
(none) β literally nothing comes back. void behavior, periodt.
π¦ Complexity π¦
Constant. no scaling drama, no surprise plot twist, just the note βConstant.β and we move on π .
π₯ 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β public member function ofstd::basic_string<CharT,Traits,Allocator>; the note next to it saysswaps the contentsπ«Ά
source/version: http://cppreference.com Β· dated 2024.06.10 Β· that was the std::basic_..._view::swap(3) page, mwah π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms