GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::basic_string::swap(3) C++ Standard Libary std::basic_string::swap(3)

std::basic_string::swap - std::basic_string::swap


void swap( basic_string& other ); (until C++17)
void swap( basic_string& other ) noexcept(/* see below */); (since C++17)
(until C++20)
constexpr void swap( basic_string& other ) noexcept(/* see below */); (since C++20)


Exchanges the contents of the string with those of other. All iterators and
references may be invalidated.


The behavior is undefined if Allocator does not propagate on swap and (since C++11)
the allocators of *this and other are unequal.


other - string to exchange the contents with


(none)


Constant.


(since
noexcept specification: C++17)
noexcept(std::allocator_traits<Allocator>::propagate_on_container_swap::value
|| std::allocator_traits<Allocator>::is_always_equal::value)

// Run this code


#include <string>
#include <iostream>


int main()
{
std::string a = "AAA";
std::string b = "BBB";


std::cout << "before swap" << '\n';
std::cout << "a: " << a << '\n';
std::cout << "b: " << b << '\n';


a.swap(b);


std::cout << "after swap" << '\n';
std::cout << "a: " << a << '\n';
std::cout << "b: " << b << '\n';
}


before swap
a: AAA
b: BBB
after swap
a: BBB
b: AAA


swap swaps the values of two objects
(function template)
swap_ranges swaps two ranges of elements
(function template)
swap swaps the contents
(C++17) (public member function of std::basic_string_view<CharT,Traits>)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.