Namensräume
Varianten
Aktionen

std::flat_multimap<Key,T,Compare,KeyContainer,MappedContainer>::operator=

Von cppreference.com
 
 
 
 
flat_multimap& operator=( const flat_multimap& other );
(1) (seit C++23)
(implizit deklariert)
flat_multimap& operator=( flat_multimap&& other );
(2) (seit C++23)
(implizit deklariert)
flat_multimap& operator=( std::initializer_list<value_type> ilist );
(3) (seit C++23)

Ersetzt den Inhalt des Container-Adapters durch den Inhalt des gegebenen Arguments.

1) Kopier-Zuweisungsoperator. Ersetzt den Inhalt durch eine Kopie des Inhalts von other. Ruft effektiv c = other.c; comp = other.comp; auf.
2) Move-Zuweisungsoperator. Ersetzt den Inhalt durch den Inhalt von other unter Verwendung von Semantikverschiebung. Ruft effektiv c = std::move(other.c); comp = std::move(other.comp); auf.
3) Ersetzt den Inhalt durch den durch die Initialisierungsliste ilist identifizierten Inhalt.

Inhalt

[bearbeiten] Parameter

Sonstiges - ein weiterer Container-Adapter, der als Quelle verwendet werden soll
ilist - Initialisierungsliste als Quelle zu verwenden

[bearbeiten] Rückgabewert

*this

[bearbeiten] Komplexität

1,2) Äquivalent zur Komplexität von operator= des zugrundeliegenden Containers.
3) Linear in der Größe von *this und ilist.

[bearbeiten] Beispiel

#include <flat_map>
#include <initializer_list>
#include <print>
#include <utility>
 
int main()
{
    std::flat_multimap<int, int> x{{1, 1}, {2, 2}, {3, 3}}, y, z;
    const auto w = {std::pair<const int, int>{4, 4}, {5, 5}, {6, 6}, {7, 7}};
 
    std::println("Initially:");
    std::println("x = {}", x);
    std::println("y = {}", y);
    std::println("z = {}", z);
 
    y = x; // overload (1)
    std::println("Copy assignment copies data from x to y:");
    std::println("x = {}", x);
    std::println("y = {}", y);
 
    z = std::move(x); // overload (2)
    std::println("Move assignment moves data from x to z, modifying both x and z:");
    std::println("x = {}", x);
    std::println("z = {}", z);
 
    z = w; // overload (3)
    std::println("Assignment of initializer_list w to z:");
    std::println("w = {}", w);
    std::println("z = {}", z);
}

Ausgabe

Initially:
x = {1: 1, 2: 2, 3: 3}
y = {}
z = {}
Copy assignment copies data from x to y:
x = {1: 1, 2: 2, 3: 3}
y = {1: 1, 2: 2, 3: 3}
Move assignment moves data from x to z, modifying both x and z:
x = {}
z = {1: 1, 2: 2, 3: 3}
Assignment of initializer_list w to z:
w = {4: 4, 5: 5, 6: 6, 7: 7}
z = {4: 4, 5: 5, 6: 6, 7: 7}

[bearbeiten] Siehe auch

konstruiert die flat_multimap
(public member function) [edit]
ersetzt die zugrunde liegenden Container
(public member function) [bearbeiten]