Spec-Zone.ru › C++

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

constexpr void swap( basic_string_view& v ) noexcept;
(since C++17)

Exchanges the view with that of v.

Parameters

v - view to swap with

Complexity

Constant.

Example

#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 & algorithm function object)
ranges::swap_ranges
(C++20)
swap
swaps the contents
(public member function of std::basic_string<CharT,Traits,Allocator>)

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/string/basic_string_view/swap

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API