[ Web Proxy ]
URL:
Viewing: http://ja.cppreference.com/cpp/string/basic_string/swap [Back]  [Original]

std::basic_string<CharT,Traits,Allocator>::swap - cppreference.com
cppreference.com

std::basic_string<CharT,Traits,Allocator>::swap

: cppreference.com
 
C++
(C++20)
(C++20)
(C++17)
(C++11)
(C++11)
(C++11)
 
 
std::basic_string
 
<tbody> </tbody> <tbody class="t-dcl-rev "> </tbody><tbody> </tbody>
void swap( basic_string& other );
(C++17)
void swap( basic_string& other ) noexcept(/* see below */);
(C++17)
(C++20)
constexpr void swap( basic_string& other ) noexcept(/* see below */);
(C++20)

other

Allocator swap *this other

(C++11)

other -

()

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

#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


Web Proxy Viewer  |  New URL  |  Original Page