This commit is contained in:
2025-10-25 03:02:53 +03:00
commit 043225d523
3416 changed files with 681196 additions and 0 deletions

View File

@@ -0,0 +1,134 @@
[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)

View File

@@ -0,0 +1,395 @@
[polymorphic.ctor]
# 20 Memory management library [[mem]](./#mem)
## 20.4 Types for composite class design [[mem.composite.types]](mem.composite.types#polymorphic.ctor)
### 20.4.2 Class template polymorphic [[polymorphic]](polymorphic#ctor)
#### 20.4.2.3 Constructors [polymorphic.ctor]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6892)
The following element applies to all functions in [polymorphic.ctor]:
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6896)
*Throws*: Nothing unless allocator_traits<Allocator>::allocate orallocator_traits<Allocator>::construct throws[.](#2.sentence-1)
[🔗](#lib:polymorphic,constructor)
`constexpr explicit polymorphic();
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6908)
*Constraints*: is_default_constructible_v<Allocator> is true[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6912)
*Mandates*:
- [(4.1)](#4.1)
is_default_constructible_v<T> is true, and
- [(4.2)](#4.2)
is_copy_constructible_v<T> is true[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6921)
*Effects*: Constructs an owned object of type T with an empty argument list
using the allocator *alloc*[.](#5.sentence-1)
[🔗](#lib:indirect,constructor)
`constexpr explicit polymorphic(allocator_arg_t, const Allocator& a);
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6933)
*Mandates*:
- [(6.1)](#6.1)
is_default_constructible_v<T> is true, and
- [(6.2)](#6.2)
is_copy_constructible_v<T> is true[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6942)
*Effects*: *alloc* is direct-non-list-initialized with a[.](#7.sentence-1)
Constructs an owned object of type T with an empty argument list
using the allocator *alloc*[.](#7.sentence-2)
[🔗](#lib:polymorphic,constructor_)
`constexpr polymorphic(const polymorphic& other);
`
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6955)
*Effects*: *alloc* is direct-non-list-initialized withallocator_traits<Allocator>::select_on_container_copy_construction(other.*alloc*)[.](#8.sentence-1)
If other is valueless, *this is valueless[.](#8.sentence-2)
Otherwise,
constructs an owned object of type U, whereU is the type of the owned object in other, with
the owned object in other using the allocator *alloc*[.](#8.sentence-3)
[🔗](#lib:polymorphic,constructor__)
`constexpr polymorphic(allocator_arg_t, const Allocator& a, const polymorphic& other);
`
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6972)
*Effects*: *alloc* is direct-non-list-initialized with a[.](#9.sentence-1)
If other is valueless, *this is valueless[.](#9.sentence-2)
Otherwise,
constructs an owned object of type U, whereU is the type of the owned object in other, with
the owned object in other using the allocator *alloc*[.](#9.sentence-3)
[🔗](#lib:polymorphic,constructor___)
`constexpr polymorphic(polymorphic&& other) noexcept;
`
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6988)
*Effects*: *alloc* is direct-non-list-initialized withstd::move(other.*alloc*)[.](#10.sentence-1)
If other is valueless, *this is valueless[.](#10.sentence-2)
Otherwise,
either *this takes ownership of the owned object of other or,
owns an object of the same type
constructed from the owned object of other considering that owned object as an rvalue,
using the allocator *alloc*[.](#10.sentence-3)
[🔗](#lib:polymorphic,constructor____)
`constexpr polymorphic(allocator_arg_t, const Allocator& a, polymorphic&& other)
noexcept(allocator_traits<Allocator>::is_always_equal::value);
`
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7010)
*Effects*: *alloc* is direct-non-list-initialized with a[.](#11.sentence-1)
If other is valueless, *this is valueless[.](#11.sentence-2)
Otherwise,
if *alloc* == other.*alloc* is true,
either constructs an object of type polymorphic that
owns the owned object of other,
making other valueless; or,
owns an object of the same type constructed from
the owned object of other considering that owned object as an rvalue[.](#11.sentence-3)
Otherwise,
if *alloc* != other.*alloc* is true,
constructs an object of type polymorphic,
considering the owned object in other as an rvalue,
using the allocator *alloc*[.](#11.sentence-4)
[🔗](#lib:polymorphic,constructor_____)
`template<class U = T>
constexpr explicit polymorphic(U&& u);
`
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7037)
*Constraints*: Where UU is remove_cvref_t<U>,
- [(12.1)](#12.1)
is_same_v<UU, polymorphic> is false,
- [(12.2)](#12.2)
derived_from<UU, T> is true,
- [(12.3)](#12.3)
is_constructible_v<UU, U> is true,
- [(12.4)](#12.4)
is_copy_constructible_v<UU> is true,
- [(12.5)](#12.5)
UU is not a specialization of in_place_type_t, and
- [(12.6)](#12.6)
is_default_constructible_v<Allocator> is true[.](#12.sentence-1)
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7055)
*Effects*: Constructs an owned object of type UU with std::forward<U>(u) using the allocator *alloc*[.](#13.sentence-1)
[🔗](#lib:polymorphic,constructor______)
`template<class U = T>
constexpr explicit polymorphic(allocator_arg_t, const Allocator& a, U&& u);
`
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7068)
*Constraints*: Where UU is remove_cvref_t<U>,
- [(14.1)](#14.1)
is_same_v<UU, polymorphic> is false,
- [(14.2)](#14.2)
derived_from<UU, T> is true,
- [(14.3)](#14.3)
is_constructible_v<UU, U> is true,
- [(14.4)](#14.4)
is_copy_constructible_v<UU> is true, and
- [(14.5)](#14.5)
UU is not a specialization of in_place_type_t[.](#14.sentence-1)
[15](#15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7084)
*Effects*: *alloc* is direct-non-list-initialized with a[.](#15.sentence-1)
Constructs an owned object of type UU with std::forward<U>(u) using the allocator *alloc*[.](#15.sentence-2)
[🔗](#lib:polymorphic,constructor_______)
`template<class U, class... Ts>
constexpr explicit polymorphic(in_place_type_t<U>, Ts&&... ts);
`
[16](#16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7098)
*Constraints*:
- [(16.1)](#16.1)
is_same_v<remove_cvref_t<U>, U> is true,
- [(16.2)](#16.2)
derived_from<U, T> is true,
- [(16.3)](#16.3)
is_constructible_v<U, Ts...> is true,
- [(16.4)](#16.4)
is_copy_constructible_v<U> is true, and
- [(16.5)](#16.5)
is_default_constructible_v<Allocator> is true[.](#16.sentence-1)
[17](#17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7113)
*Effects*: Constructs an owned object of type U withstd::forward<Ts>(ts)... using the allocator *alloc*[.](#17.sentence-1)
[🔗](#lib:polymorphic,constructor________)
`template<class U, class... Ts>
constexpr explicit polymorphic(allocator_arg_t, const Allocator& a,
in_place_type_t<U>, Ts&&... ts);
`
[18](#18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7128)
*Constraints*:
- [(18.1)](#18.1)
is_same_v<remove_cvref_t<U>, U> is true,
- [(18.2)](#18.2)
derived_from<U, T> is true,
- [(18.3)](#18.3)
is_constructible_v<U, Ts...> is true, and
- [(18.4)](#18.4)
is_copy_constructible_v<U> is true[.](#18.sentence-1)
[19](#19)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7141)
*Effects*: *alloc* is direct-non-list-initialized with a[.](#19.sentence-1)
Constructs an owned object of type U withstd::forward<Ts>(ts)... using the allocator *alloc*[.](#19.sentence-2)
[🔗](#lib:polymorphic,constructor_________)
`template<class U, class I, class... Us>
constexpr explicit polymorphic(in_place_type_t<U>, initializer_list<I> ilist, Us&&... us);
`
[20](#20)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7156)
*Constraints*:
- [(20.1)](#20.1)
is_same_v<remove_cvref_t<U>, U> is true,
- [(20.2)](#20.2)
derived_from<U, T> is true,
- [(20.3)](#20.3)
is_constructible_v<U, initializer_list<I>&, Us...> is true,
- [(20.4)](#20.4)
is_copy_constructible_v<U> is true, and
- [(20.5)](#20.5)
is_default_constructible_v<Allocator> is true[.](#20.sentence-1)
[21](#21)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7171)
*Effects*: Constructs an owned object of type U with
the arguments ilist, std::forward<Us>(us)... using the allocator *alloc*[.](#21.sentence-1)
[🔗](#lib:polymorphic,constructor__________)
`template<class U, class I, class... Us>
constexpr explicit polymorphic(allocator_arg_t, const Allocator& a,
in_place_type_t<U>, initializer_list<I> ilist, Us&&... us);
`
[22](#22)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7186)
*Constraints*:
- [(22.1)](#22.1)
is_same_v<remove_cvref_t<U>, U> is true,
- [(22.2)](#22.2)
derived_from<U, T> is true,
- [(22.3)](#22.3)
is_constructible_v<U, initializer_list<I>&, Us...> is true, and
- [(22.4)](#22.4)
is_copy_constructible_v<U> is true[.](#22.sentence-1)
[23](#23)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7200)
*Effects*: *alloc* is direct-non-list-initialized with a[.](#23.sentence-1)
Constructs an owned object of type U with the argumentsilist, std::forward<Us>(us)... using the allocator *alloc*[.](#23.sentence-2)

View File

@@ -0,0 +1,28 @@
[polymorphic.dtor]
# 20 Memory management library [[mem]](./#mem)
## 20.4 Types for composite class design [[mem.composite.types]](mem.composite.types#polymorphic.dtor)
### 20.4.2 Class template polymorphic [[polymorphic]](polymorphic#dtor)
#### 20.4.2.4 Destructor [polymorphic.dtor]
[🔗](#lib:polymorphic,destructor)
`constexpr ~polymorphic();
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7216)
*Mandates*: T is a complete type[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7220)
*Effects*: If *this is not valueless,
destroys the owned object using allocator_traits<Allocator>::destroy and
then the storage is deallocated[.](#2.sentence-1)

View File

@@ -0,0 +1,103 @@
[polymorphic.general]
# 20 Memory management library [[mem]](./#mem)
## 20.4 Types for composite class design [[mem.composite.types]](mem.composite.types#polymorphic.general)
### 20.4.2 Class template polymorphic [[polymorphic]](polymorphic#general)
#### 20.4.2.1 General [polymorphic.general]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6758)
A polymorphic object manages the lifetime of an owned object[.](#1.sentence-1)
A polymorphic object may own objects of
different types at different points in its lifetime[.](#1.sentence-2)
A polymorphic object is[*valueless*](#def:valueless,polymorphic_object "20.4.2.1General[polymorphic.general]") if it has no owned object[.](#1.sentence-3)
A polymorphic object may become valueless only after it has been moved from[.](#1.sentence-4)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6767)
In every specialization polymorphic<T, Allocator>,
if the type allocator_traits<Allocator>::value_type is not the same type as T, the program is ill-formed[.](#2.sentence-1)
Every object of type polymorphic<T, Allocator> uses an object of type Allocator to
allocate and free storage for the owned object as needed[.](#2.sentence-2)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6775)
Constructing an owned object of type U with args... using the allocator a means callingallocator_traits<Allocator>::construct(a, *p*, args...) whereargs is an expression pack,a is an allocator, and*p* points to storage suitable for an owned object of type U[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6783)
The member *alloc* is used for
any memory allocation and element construction
performed by member functions
during the lifetime of each polymorphic value object, or
until the allocator is replaced[.](#4.sentence-1)
The allocator may be replaced only via
assignment or swap()[.](#4.sentence-2)
Allocator replacement is performed by
copy assignment,
move assignment, or
swapping of the allocator
only if ([[container.reqmts]](container.reqmts "23.2.2.2Container requirements")):
- [(4.1)](#4.1)
allocator_traits<Allocator>::propagate_on_container_copy_assignment::value, or
- [(4.2)](#4.2)
allocator_traits<Allocator>::propagate_on_container_move_assignment::value, or
- [(4.3)](#4.3)
allocator_traits<Allocator>::propagate_on_container_swap::value
is true within the implementation of
the corresponding polymorphic operation[.](#4.sentence-3)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6807)
A program that instantiates the definition of polymorphic for
a non-object type,
an array type,in_place_t,
a specialization of in_place_type_t, or
a cv-qualified type
is ill-formed[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6816)
The template parameter T of polymorphic may be an incomplete type[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6820)
The template parameter Allocator of polymorphic shall meet the requirements of *Cpp17Allocator*[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6824)
If a program declares an explicit or
partial specialization of polymorphic,
the behavior is undefined[.](#8.sentence-1)

View File

@@ -0,0 +1,67 @@
[polymorphic.obs]
# 20 Memory management library [[mem]](./#mem)
## 20.4 Types for composite class design [[mem.composite.types]](mem.composite.types#polymorphic.obs)
### 20.4.2 Class template polymorphic [[polymorphic]](polymorphic#obs)
#### 20.4.2.6 Observers [polymorphic.obs]
[🔗](#lib:operator*,polymorphic)
`constexpr const T& operator*() const noexcept;
constexpr T& operator*() noexcept;
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7355)
*Preconditions*: *this is not valueless[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7359)
*Returns*: A reference to the owned object[.](#2.sentence-1)
[🔗](#lib:operator-%3e,polymorphic)
`constexpr const_pointer operator->() const noexcept;
constexpr pointer operator->() noexcept;
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7371)
*Preconditions*: *this is not valueless[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7375)
*Returns*: A pointer to the owned object[.](#4.sentence-1)
[🔗](#lib:valueless_after_move,polymorphic)
`constexpr bool valueless_after_move() const noexcept;
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7386)
*Returns*: true if *this is valueless, otherwise false[.](#5.sentence-1)
[🔗](#lib:get_allocator,polymorphic)
`constexpr allocator_type get_allocator() const noexcept;
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7397)
*Returns*: *alloc*[.](#6.sentence-1)

View File

@@ -0,0 +1,55 @@
[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)

View File

@@ -0,0 +1,15 @@
[polymorphic.syn]
# 20 Memory management library [[mem]](./#mem)
## 20.4 Types for composite class design [[mem.composite.types]](mem.composite.types#polymorphic.syn)
### 20.4.2 Class template polymorphic [[polymorphic]](polymorphic#syn)
#### 20.4.2.2 Synopsis [polymorphic.syn]
[🔗](#lib:polymorphic)
namespace std {template<class T, class Allocator = allocator<T>>class polymorphic {public:using value_type = T; using allocator_type = Allocator; using pointer = typename allocator_traits<Allocator>::pointer; using const_pointer = typename allocator_traits<Allocator>::const_pointer; // [[polymorphic.ctor]](polymorphic.ctor "20.4.2.3Constructors"), constructorsconstexpr explicit polymorphic(); constexpr explicit polymorphic(allocator_arg_t, const Allocator& a); constexpr polymorphic(const polymorphic& other); constexpr polymorphic(allocator_arg_t, const Allocator& a, const polymorphic& other); constexpr polymorphic(polymorphic&& other) noexcept; constexpr polymorphic(allocator_arg_t, const Allocator& a, polymorphic&& other)noexcept(*see below*); template<class U = T>constexpr explicit polymorphic(U&& u); template<class U = T>constexpr explicit polymorphic(allocator_arg_t, const Allocator& a, U&& u); template<class U, class... Ts>constexpr explicit polymorphic(in_place_type_t<U>, Ts&&... ts); template<class U, class... Ts>constexpr explicit polymorphic(allocator_arg_t, const Allocator& a,
in_place_type_t<U>, Ts&&... ts); template<class U, class I, class... Us>constexpr explicit polymorphic(in_place_type_t<U>, initializer_list<I> ilist, Us&&... us); template<class U, class I, class... Us>constexpr explicit polymorphic(allocator_arg_t, const Allocator& a,
in_place_type_t<U>, initializer_list<I> ilist, Us&&... us); // [[polymorphic.dtor]](polymorphic.dtor "20.4.2.4Destructor"), destructorconstexpr ~polymorphic(); // [[polymorphic.assign]](polymorphic.assign "20.4.2.5Assignment"), assignmentconstexpr polymorphic& operator=(const polymorphic& other); constexpr polymorphic& operator=(polymorphic&& other) noexcept(*see below*); // [[polymorphic.obs]](polymorphic.obs "20.4.2.6Observers"), observersconstexpr const T& operator*() const noexcept; constexpr T& operator*() noexcept; constexpr const_pointer operator->() const noexcept; constexpr pointer operator->() noexcept; constexpr bool valueless_after_move() const noexcept; constexpr allocator_type get_allocator() const noexcept; // [[polymorphic.swap]](polymorphic.swap "20.4.2.7Swap"), swapconstexpr void swap(polymorphic& other) noexcept(*see below*); friend constexpr void swap(polymorphic& lhs, polymorphic& rhs) noexcept(*see below*); private: Allocator *alloc* = Allocator(); // *exposition only*};}