[polymorphic.swap] # 20 Memory management library [[mem]](./#mem) ## 20.4 Types for composite class design [[mem.composite.types]](mem.composite.types#polymorphic.swap) ### 20.4.2 Class template polymorphic [[polymorphic]](polymorphic#swap) #### 20.4.2.7 Swap [polymorphic.swap] [🔗](#lib:swap,polymorphic) `constexpr void swap(polymorphic& other) noexcept(allocator_traits::propagate_on_container_swap::value || allocator_traits::is_always_equal::value); ` [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7412) *Preconditions*: If allocator_traits​::​propagate_on_container_swap​::​value is true, thenAllocator meets the *Cpp17Swappable* requirements[.](#1.sentence-1) Otherwise get_allocator() == other. get_allocator() is true[.](#1.sentence-2) [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7419) *Effects*: Swaps the states of *this and other, exchanging owned objects or valueless states[.](#2.sentence-1) If allocator_traits​::​propagate_on_container_swap​::​value is true, then the allocators of *this and other are exchanged by calling swap as described in [[swappable.requirements]](swappable.requirements "16.4.4.3 Swappable requirements")[.](#2.sentence-2) Otherwise, the allocators are not swapped[.](#2.sentence-3) [*Note [1](#note-1)*: Does not call swap on the owned objects directly[.](#2.sentence-4) — *end note*] [🔗](#itemdecl:2) `constexpr void swap(polymorphic& lhs, polymorphic& rhs) noexcept(noexcept(lhs.swap(rhs))); ` [3](#3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7442) *Effects*: Equivalent to lhs.swap(rhs)[.](#3.sentence-1)