Espacios de nombres
Variantes

std::swap(std::flat_set)

De cppreference.com
 
 
 
 
Definido en el archivo de encabezado <...>
friend void swap( std::flat_set& lhs, std::flat_set& rhs ) noexcept;
(desde C++23)

Especializa el algoritmo std::swap para std::flat_set. Intercambia el contenido de lhs y rhs. Llama a lhs.swap(rhs).

Parámetros

lhs, rhs - Los contenedores cuyo contenido hay que intercambiar.

Valor de retorno

(Ninguno)

Complejidad

La misma que intercambiar los contenedores subyacentes.

Ejemplo

#include <algorithm>
#include <iostream>
#include <...>

int main()
{
    std::flat_set<int> alice{1, 2, 3};
    std::flat_set<int> bob{7, 8, 9, 10};

    auto print = [](const int& n) { std::cout << ' ' << n; };

    // Imprimir estado antes del intercambio
    std::cout << "Alice:";
    std::for_each(alice.begin(), alice.end(), print);
    std::cout << "\nBobby:";
    std::for_each(bob.begin(), bob.end(), print);
    std::cout << '\n';

    std::cout << "-- INTERCAMBIO\n";
    std::swap(alice, bob);

    // Imprimir estado después del intercambio
    std::cout << "Alice:";
    std::for_each(alice.begin(), alice.end(), print);
    std::cout << "\nBobby:";
    std::for_each(bob.begin(), bob.end(), print);
    std::cout << '\n';
}

Salida:

Alice: 1 2 3
Bobby: 7 8 9 10
-- INTERCAMBIO
Alice: 7 8 9 10
Bobby: 1 2 3

Véase también

(C++23)
Intercambia el contenido.
(función miembro pública) [editar]
Morty Proxy This is a proxified and sanitized view of the page, visit original site.