Spec-Zone.ru › C++

std::flat_multiset<Key,Compare,KeyContainer>::operator=

flat_multiset& operator=( const flat_multiset& other );
(1) (начиная с C++23)
(объявлен неявно)
flat_multiset& operator=( flat_multiset&& other );
(2) (начиная с C++23)
(объявлен неявно)
flat_multiset& operator=( std::initializer_list<key_type> ilist );
(3) (начиная с C++23)

Заменяет содержимое адаптера контейнера содержимым указанного аргумента.

1) Оператор копирующего присваивания. Заменяет содержимое копией содержимого other. Фактически вызывает c = other.c; comp = other.comp;.
2) Оператор перемещающего присваивания. Заменяет содержимое содержимым other, используя семантику перемещения. Фактически вызывает c = std::move(other.c); comp = std::move(other.comp);.
3) Заменяет содержимое элементами из списка инициализации ilist.

Параметры

other - другой адаптер контейнера, используемый в качестве источника
ilist - список инициализации, используемый в качестве источника

Возвращаемое значение

*this

Сложность

1,2) Эквивалентна сложности operator= базового контейнера.
3) Линейная относительно размера *this и ilist.

Пример

#include <flat_set>
#include <initializer_list>
#include <print>

int main()
{
    std::flat_multiset<int> x{1, 2, 3}, y, z;
    const auto w = {4, 5, 6, 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);
}

Вывод:

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

См. также

конструктор
создаёт flat_multiset
(открытая функция-член)
replace
заменяет базовый контейнер
(открытая функция-член)

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/container/flat_multiset/operator%3D

Spec-Zone.ru

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