[indirect.assign]

# 20 Memory management library [[mem]](./#mem)

## 20.4 Types for composite class design [[mem.composite.types]](mem.composite.types#indirect.assign)

### 20.4.1 Class template indirect [[indirect]](indirect#assign)

#### 20.4.1.5 Assignment [indirect.assign]

[ð](#lib:operator=,indirect)

`constexpr indirect& operator=(const indirect& other);
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6358)

*Mandates*: 

- [(1.1)](#1.1)

is_copy_assignable_v<T> is true, and

- [(1.2)](#1.2)

is_copy_constructible_v<T> is true[.](#1.sentence-1)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6368)

*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 valueless,*this becomes valueless and
the owned object in *this, if any,
is destroyed using allocator_traits<Allocator>​::​destroy and
then the storage is deallocated[.](#2.2.sentence-1)

- [(2.3)](#2.3)

  Otherwise,
if *alloc* == other.*alloc* is true and*this is not valueless,
equivalent to **this = *other[.](#2.3.sentence-1)

- [(2.4)](#2.4)

  Otherwise a new owned object is constructed in *this using allocator_traits<Allocator>​::​con  
struct 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.4.sentence-1)

- [(2.5)](#2.5)

  The previously owned object in *this, if any,
is destroyed using allocator_traits<Allocator>​::​  
destroy and
then the storage is deallocated[.](#2.5.sentence-1)

- [(2.6)](#2.6)

  If the allocator needs updating,
the allocator in *this is replaced with
a copy of the allocator in other[.](#2.6.sentence-1)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6415)

*Returns*: A reference to *this[.](#3.sentence-1)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6419)

*Remarks*: If any exception is thrown,
the result of the expression this->valueless_after_move() remains unchanged[.](#4.sentence-1)

If an exception is thrown during
the call to T's selected copy constructor, no effect[.](#4.sentence-2)

If an exception is thrown during the call to T's copy assignment,
the state of its owned object
is as defined by the exception safety guarantee ofT's copy assignment[.](#4.sentence-3)

[ð](#lib:operator=,indirect_)

`constexpr indirect& operator=(indirect&& 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#L6440)

*Mandates*: is_copy_constructible_t<T> is true[.](#5.sentence-1)

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6444)

*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 other is valueless,*this becomes valueless and
the owned object in *this, if any,
is 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,
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.3.sentence-1)

- [(6.4)](#6.4)

  Otherwise,
constructs a new owned object with
the owned object of other as the argument as an rvalue,
using either
the allocator in *this or
the allocator in other if the allocator needs updating[.](#6.4.sentence-1)

- [(6.5)](#6.5)

  The previously owned object in *this, if any,
is destroyed using allocator_traits<Allocator>​::​  
destroy and
then the storage is deallocated[.](#6.5.sentence-1)

- [(6.6)](#6.6)

  If the allocator needs updating,
the allocator in *this is replaced with
a copy of the allocator in other[.](#6.6.sentence-1)

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6493)

*Postconditions*: other is valueless[.](#7.sentence-1)

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6497)

*Returns*: A reference to *this[.](#8.sentence-1)

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6501)

*Remarks*: If any exception is thrown,
there are no effects on *this or other[.](#9.sentence-1)

[ð](#lib:operator=,indirect__)

`template<class U = T>
  constexpr indirect& operator=(U&& u);
`

[10](#10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6514)

*Constraints*: 

- [(10.1)](#10.1)

is_same_v<remove_cvref_t<U>, indirect> is false,

- [(10.2)](#10.2)

is_constructible_v<T, U> is true, and

- [(10.3)](#10.3)

is_assignable_v<T&, U> is true[.](#10.sentence-1)

[11](#11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6525)

*Effects*: If *this is valueless then
constructs an owned object of type T with std​::​forward<U>(u) using the allocator *alloc*[.](#11.sentence-1)

Otherwise,
equivalent to **this = std​::​forward<U>(u)[.](#11.sentence-2)

[12](#12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6533)

*Returns*: A reference to *this[.](#12.sentence-1)
