135 lines
4.1 KiB
Markdown
135 lines
4.1 KiB
Markdown
[polymorphic.assign]
|
||
|
||
# 20 Memory management library [[mem]](./#mem)
|
||
|
||
## 20.4 Types for composite class design [[mem.composite.types]](mem.composite.types#polymorphic.assign)
|
||
|
||
### 20.4.2 Class template polymorphic [[polymorphic]](polymorphic#assign)
|
||
|
||
#### 20.4.2.5 Assignment [polymorphic.assign]
|
||
|
||
[ð](#lib:operator=,polymorphic)
|
||
|
||
`constexpr polymorphic& operator=(const polymorphic& other);
|
||
`
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7236)
|
||
|
||
*Mandates*: T is a complete type[.](#1.sentence-1)
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7240)
|
||
|
||
*Effects*: If addressof(other) == this is true, there are no effects[.](#2.sentence-1)
|
||
|
||
Otherwise:
|
||
|
||
- [(2.1)](#2.1)
|
||
|
||
The allocator needs updating ifallocator_traits<Allocator>::propagate_on_container_copy_assignment::value is true[.](#2.1.sentence-1)
|
||
|
||
- [(2.2)](#2.2)
|
||
|
||
If other is not valueless,
|
||
a new owned object is constructed in *this usingallocator_traits<Allocator>::construct with
|
||
the owned object from other as the argument, using either
|
||
the allocator in *this or
|
||
the allocator in other if the allocator needs updating[.](#2.2.sentence-1)
|
||
|
||
- [(2.3)](#2.3)
|
||
|
||
The previously owned object in *this, if any,
|
||
is destroyed using allocator_traits<Allocator>::
|
||
destroy and
|
||
then the storage is deallocated[.](#2.3.sentence-1)
|
||
|
||
- [(2.4)](#2.4)
|
||
|
||
If the allocator needs updating,
|
||
the allocator in *this is replaced with
|
||
a copy of the allocator in other[.](#2.4.sentence-1)
|
||
|
||
[3](#3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7272)
|
||
|
||
*Returns*: A reference to *this[.](#3.sentence-1)
|
||
|
||
[4](#4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7276)
|
||
|
||
*Remarks*: If any exception is thrown, there are no effects on *this[.](#4.sentence-1)
|
||
|
||
[ð](#lib:operator=,polymorphic_)
|
||
|
||
`constexpr polymorphic& operator=(polymorphic&& other)
|
||
noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
|
||
allocator_traits<Allocator>::is_always_equal::value);
|
||
`
|
||
|
||
[5](#5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7289)
|
||
|
||
*Mandates*: If allocator_traits<Allocator>::is_always_equal::value is false,T is a complete type[.](#5.sentence-1)
|
||
|
||
[6](#6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7294)
|
||
|
||
*Effects*: If addressof(other) == this is true, there are no effects[.](#6.sentence-1)
|
||
|
||
Otherwise:
|
||
|
||
- [(6.1)](#6.1)
|
||
|
||
The allocator needs updating ifallocator_traits<Allocator>::propagate_on_container_move_assignment::value is true[.](#6.1.sentence-1)
|
||
|
||
- [(6.2)](#6.2)
|
||
|
||
If *alloc* == other.*alloc* is true,
|
||
swaps the owned objects in *this and other;
|
||
the owned object in other, if any,
|
||
is then destroyed using allocator_traits<Allocator>::destroy and
|
||
then the storage is deallocated[.](#6.2.sentence-1)
|
||
|
||
- [(6.3)](#6.3)
|
||
|
||
Otherwise,
|
||
if *alloc* != other.*alloc* is true;
|
||
if other is not valueless,
|
||
a new owned object is constructed in *this using allocator_traits<Allocator>::construct with
|
||
the owned object from other as the argument as an rvalue,
|
||
using either the allocator in *this or
|
||
the allocator in other if the allocator needs updating[.](#6.3.sentence-1)
|
||
|
||
- [(6.4)](#6.4)
|
||
|
||
The previously owned object in *this, if any,
|
||
is destroyed using allocator_traits<Allocator>::
|
||
destroy and
|
||
then the storage is deallocated[.](#6.4.sentence-1)
|
||
|
||
- [(6.5)](#6.5)
|
||
|
||
If the allocator needs updating,
|
||
the allocator in *this is replaced with
|
||
a copy of the allocator in other[.](#6.5.sentence-1)
|
||
|
||
[7](#7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7336)
|
||
|
||
*Returns*: A reference to *this[.](#7.sentence-1)
|
||
|
||
[8](#8)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7340)
|
||
|
||
*Remarks*: If any exception is thrown,
|
||
there are no effects on *this or other[.](#8.sentence-1)
|