Namespaces
Variants

std::basic_string_view<CharT,Traits>:: swap

From cppreference.net
constexpr void swap ( basic_string_view & v ) noexcept ;
(C++17부터)

뷰를 v 와 교환합니다.

목차

매개변수

v - 교체할 뷰

반환값

(없음)

복잡도

상수.

예제

#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';
}

출력:

Before swap:
a = AAA
b = BBBB
After swap:
a = BBBB
b = AAA

참고 항목

두 객체의 값을 교환
(함수 템플릿)
두 요소 범위를 교환
(함수 템플릿)
내용을 교환
( std::basic_string<CharT,Traits,Allocator> 의 public 멤버 함수)