Files
2025-10-25 03:02:53 +03:00

56 lines
1.8 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[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<Allocator>::propagate_on_container_swap::value ||
allocator_traits<Allocator>::is_always_equal::value);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7412)
*Preconditions*: If allocator_traits<Allocator>::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<Allocator>::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.3Swappable 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)