std::hive<T,Allocator>::operator=
hive& operator=( const hive& other ); | (1) | (since C++26) |
hive& operator=( hive&& other ) noexcept(/* see description */); | (2) | (since C++26) |
hive& operator=( std::initializer_list<T> ilist ); | (3) | (since C++26) |
Replaces the contents of the container.
1) All elements in
*this are either copy-assigned to, or destroyed. All elements in other are copied into *this. The relative order of copied elements is preserved. current-limits are unchanged.
2) Each element in
Let *this is either move-assigned to, or destroyed.EXCEPT be std::allocator_traits<Allocator>::propagate_on_container_move_assignment::value || std::allocator_traits<Allocator>::is_always_equal::valueLet
ALLOC be std::allocator_traits<Allocator>::propagate_on_container_move_assignment::value || this->get_allocator() == other.get_allocator()
- If
ALLOCis true,current-limitsis set toother.current-limitsand each element block is moved fromotherinto*this.
Pointers and references to the elements ofothernow refer to those same elements but as members of*this.
Iterators referring to the elements ofotherwill continue to refer to their elements, but they now behave as iterators into*this, not intoother. - If
ALLOCis false, each element inotheris moved into*this.
References, pointers and iterators referring to the elements ofother, as well asend()iterator ofother, are invalidated.
After this operator
other.empty() is true. The relative order of the elements of *this is the same as that of the elements of other before the call.
3) Replaces the contents with those identified by initializer list
ilist. All existing elements of *this are either assigned to or destroyed.Parameters
| other | - | another hive to use as data source |
| ilist | - | initializer list to use as data source |
| Type requirements | ||
-T must meet the requirements of CopyAssignable and CopyInsertable in order to use overloads (1,3). |
||
-T must meet the requirements of MoveAssignable and MoveInsertable in order to use overload (2). (Only if EXCEPT is false). |
||
Return value
*this
Complexity
1) Linear in the size of
*this and other.
2) Linear in the size of
*this. If ALLOC is false (which means the allocators do not compare equal and do not propagate), also linear in the size of other.
3) Linear in the size of
*this and ilist.Exceptions
1,3) May throw implementation-defined exceptions.
2)
noexcept specification: noexcept(/*EXCEPT*/)
Example
#include <hive>
#include <initializer_list>
#include <print>
#include <utility>
int main()
{
std::hive<int> a{1, 2, 3}, b, c;
std::println("Initially:");
std::println("a = {}", a);
std::println("b = {}", b);
std::println("c = {}", c);
b = a; // overload (1)
std::println("Copy assignment copies data from a to b:");
std::println("a = {}", a);
std::println("b = {}", b);
c = std::move(a); // overload (2)
std::println("Move assignment moves data from a to c, modifying both a and c:");
std::println("a = {}", a);
std::println("c = {}", c);
c = {4, 5, 6, 7}; // overload (3)
std::println("Assignment of initializer_list to c:");
std::println("c = {}", c);
}
Possible output:
Initially: a = [1, 2, 3] b = [] c = [] Copy assignment copies data from a to b: a = [1, 2, 3] b = [1, 2, 3] Move assignment moves data from a to c, modifying both a and c: a = [] c = [1, 2, 3] Assignment of initializer_list to c: c = [4, 5, 6, 7]
See also
constructs the hive (public member function) |
|
| assigns values to the container (public member function) |
|
| assigns a range of values to the container (public member function) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/container/hive/operator%3D