Init
This commit is contained in:
755
cppdraft/polymorphic.md
Normal file
755
cppdraft/polymorphic.md
Normal file
@@ -0,0 +1,755 @@
|
||||
[polymorphic]
|
||||
|
||||
# 20 Memory management library [[mem]](./#mem)
|
||||
|
||||
## 20.4 Types for composite class design [[mem.composite.types]](mem.composite.types#polymorphic)
|
||||
|
||||
### 20.4.2 Class template polymorphic [polymorphic]
|
||||
|
||||
#### [20.4.2.1](#general) General [[polymorphic.general]](polymorphic.general)
|
||||
|
||||
[1](#general-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6758)
|
||||
|
||||
A polymorphic object manages the lifetime of an owned object[.](#general-1.sentence-1)
|
||||
|
||||
A polymorphic object may own objects of
|
||||
different types at different points in its lifetime[.](#general-1.sentence-2)
|
||||
|
||||
A polymorphic object is[*valueless*](#def:valueless,polymorphic_object "20.4.2.1 General [polymorphic.general]") if it has no owned object[.](#general-1.sentence-3)
|
||||
|
||||
A polymorphic object may become valueless only after it has been moved from[.](#general-1.sentence-4)
|
||||
|
||||
[2](#general-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[.](#general-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[.](#general-2.sentence-2)
|
||||
|
||||
[3](#general-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[.](#general-3.sentence-1)
|
||||
|
||||
[4](#general-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[.](#general-4.sentence-1)
|
||||
|
||||
The allocator may be replaced only via
|
||||
assignment or swap()[.](#general-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.2 Container requirements")):
|
||||
|
||||
- [(4.1)](#general-4.1)
|
||||
|
||||
allocator_traits<Allocator>::propagate_on_container_copy_assignment::value, or
|
||||
|
||||
- [(4.2)](#general-4.2)
|
||||
|
||||
allocator_traits<Allocator>::propagate_on_container_move_assignment::value, or
|
||||
|
||||
- [(4.3)](#general-4.3)
|
||||
|
||||
allocator_traits<Allocator>::propagate_on_container_swap::value
|
||||
|
||||
is true within the implementation of
|
||||
the corresponding polymorphic operation[.](#general-4.sentence-3)
|
||||
|
||||
[5](#general-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[.](#general-5.sentence-1)
|
||||
|
||||
[6](#general-6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6816)
|
||||
|
||||
The template parameter T of polymorphic may be an incomplete type[.](#general-6.sentence-1)
|
||||
|
||||
[7](#general-7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6820)
|
||||
|
||||
The template parameter Allocator of polymorphic shall meet the requirements of *Cpp17Allocator*[.](#general-7.sentence-1)
|
||||
|
||||
[8](#general-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[.](#general-8.sentence-1)
|
||||
|
||||
#### [20.4.2.2](#syn) Synopsis [[polymorphic.syn]](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]](#ctor "20.4.2.3 Constructors"), 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]](#dtor "20.4.2.4 Destructor"), destructorconstexpr ~polymorphic(); // [[polymorphic.assign]](#assign "20.4.2.5 Assignment"), assignmentconstexpr polymorphic& operator=(const polymorphic& other); constexpr polymorphic& operator=(polymorphic&& other) noexcept(*see below*); // [[polymorphic.obs]](#obs "20.4.2.6 Observers"), 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]](#swap "20.4.2.7 Swap"), 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*};}
|
||||
|
||||
#### [20.4.2.3](#ctor) Constructors [[polymorphic.ctor]](polymorphic.ctor)
|
||||
|
||||
[1](#ctor-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6892)
|
||||
|
||||
The following element applies to all functions in [[polymorphic.ctor]](#ctor "20.4.2.3 Constructors"):
|
||||
|
||||
[2](#ctor-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6896)
|
||||
|
||||
*Throws*: Nothing unless allocator_traits<Allocator>::allocate orallocator_traits<Allocator>::construct throws[.](#ctor-2.sentence-1)
|
||||
|
||||
[ð](#lib:polymorphic,constructor)
|
||||
|
||||
`constexpr explicit polymorphic();
|
||||
`
|
||||
|
||||
[3](#ctor-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6908)
|
||||
|
||||
*Constraints*: is_default_constructible_v<Allocator> is true[.](#ctor-3.sentence-1)
|
||||
|
||||
[4](#ctor-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6912)
|
||||
|
||||
*Mandates*:
|
||||
|
||||
- [(4.1)](#ctor-4.1)
|
||||
|
||||
is_default_constructible_v<T> is true, and
|
||||
|
||||
- [(4.2)](#ctor-4.2)
|
||||
|
||||
is_copy_constructible_v<T> is true[.](#ctor-4.sentence-1)
|
||||
|
||||
[5](#ctor-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*[.](#ctor-5.sentence-1)
|
||||
|
||||
[ð](#lib:indirect,constructor)
|
||||
|
||||
`constexpr explicit polymorphic(allocator_arg_t, const Allocator& a);
|
||||
`
|
||||
|
||||
[6](#ctor-6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6933)
|
||||
|
||||
*Mandates*:
|
||||
|
||||
- [(6.1)](#ctor-6.1)
|
||||
|
||||
is_default_constructible_v<T> is true, and
|
||||
|
||||
- [(6.2)](#ctor-6.2)
|
||||
|
||||
is_copy_constructible_v<T> is true[.](#ctor-6.sentence-1)
|
||||
|
||||
[7](#ctor-7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6942)
|
||||
|
||||
*Effects*: *alloc* is direct-non-list-initialized with a[.](#ctor-7.sentence-1)
|
||||
|
||||
Constructs an owned object of type T with an empty argument list
|
||||
using the allocator *alloc*[.](#ctor-7.sentence-2)
|
||||
|
||||
[ð](#lib:polymorphic,constructor_)
|
||||
|
||||
`constexpr polymorphic(const polymorphic& other);
|
||||
`
|
||||
|
||||
[8](#ctor-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*)[.](#ctor-8.sentence-1)
|
||||
|
||||
If other is valueless, *this is valueless[.](#ctor-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*[.](#ctor-8.sentence-3)
|
||||
|
||||
[ð](#lib:polymorphic,constructor__)
|
||||
|
||||
`constexpr polymorphic(allocator_arg_t, const Allocator& a, const polymorphic& other);
|
||||
`
|
||||
|
||||
[9](#ctor-9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6972)
|
||||
|
||||
*Effects*: *alloc* is direct-non-list-initialized with a[.](#ctor-9.sentence-1)
|
||||
|
||||
If other is valueless, *this is valueless[.](#ctor-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*[.](#ctor-9.sentence-3)
|
||||
|
||||
[ð](#lib:polymorphic,constructor___)
|
||||
|
||||
`constexpr polymorphic(polymorphic&& other) noexcept;
|
||||
`
|
||||
|
||||
[10](#ctor-10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L6988)
|
||||
|
||||
*Effects*: *alloc* is direct-non-list-initialized withstd::move(other.*alloc*)[.](#ctor-10.sentence-1)
|
||||
|
||||
If other is valueless, *this is valueless[.](#ctor-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*[.](#ctor-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](#ctor-11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7010)
|
||||
|
||||
*Effects*: *alloc* is direct-non-list-initialized with a[.](#ctor-11.sentence-1)
|
||||
|
||||
If other is valueless, *this is valueless[.](#ctor-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[.](#ctor-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*[.](#ctor-11.sentence-4)
|
||||
|
||||
[ð](#lib:polymorphic,constructor_____)
|
||||
|
||||
`template<class U = T>
|
||||
constexpr explicit polymorphic(U&& u);
|
||||
`
|
||||
|
||||
[12](#ctor-12)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7037)
|
||||
|
||||
*Constraints*: Where UU is remove_cvref_t<U>,
|
||||
|
||||
- [(12.1)](#ctor-12.1)
|
||||
|
||||
is_same_v<UU, polymorphic> is false,
|
||||
|
||||
- [(12.2)](#ctor-12.2)
|
||||
|
||||
derived_from<UU, T> is true,
|
||||
|
||||
- [(12.3)](#ctor-12.3)
|
||||
|
||||
is_constructible_v<UU, U> is true,
|
||||
|
||||
- [(12.4)](#ctor-12.4)
|
||||
|
||||
is_copy_constructible_v<UU> is true,
|
||||
|
||||
- [(12.5)](#ctor-12.5)
|
||||
|
||||
UU is not a specialization of in_place_type_t, and
|
||||
|
||||
- [(12.6)](#ctor-12.6)
|
||||
|
||||
is_default_constructible_v<Allocator> is true[.](#ctor-12.sentence-1)
|
||||
|
||||
[13](#ctor-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*[.](#ctor-13.sentence-1)
|
||||
|
||||
[ð](#lib:polymorphic,constructor______)
|
||||
|
||||
`template<class U = T>
|
||||
constexpr explicit polymorphic(allocator_arg_t, const Allocator& a, U&& u);
|
||||
`
|
||||
|
||||
[14](#ctor-14)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7068)
|
||||
|
||||
*Constraints*: Where UU is remove_cvref_t<U>,
|
||||
|
||||
- [(14.1)](#ctor-14.1)
|
||||
|
||||
is_same_v<UU, polymorphic> is false,
|
||||
|
||||
- [(14.2)](#ctor-14.2)
|
||||
|
||||
derived_from<UU, T> is true,
|
||||
|
||||
- [(14.3)](#ctor-14.3)
|
||||
|
||||
is_constructible_v<UU, U> is true,
|
||||
|
||||
- [(14.4)](#ctor-14.4)
|
||||
|
||||
is_copy_constructible_v<UU> is true, and
|
||||
|
||||
- [(14.5)](#ctor-14.5)
|
||||
|
||||
UU is not a specialization of in_place_type_t[.](#ctor-14.sentence-1)
|
||||
|
||||
[15](#ctor-15)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7084)
|
||||
|
||||
*Effects*: *alloc* is direct-non-list-initialized with a[.](#ctor-15.sentence-1)
|
||||
|
||||
Constructs an owned object of type UU with std::forward<U>(u) using the allocator *alloc*[.](#ctor-15.sentence-2)
|
||||
|
||||
[ð](#lib:polymorphic,constructor_______)
|
||||
|
||||
`template<class U, class... Ts>
|
||||
constexpr explicit polymorphic(in_place_type_t<U>, Ts&&... ts);
|
||||
`
|
||||
|
||||
[16](#ctor-16)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7098)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(16.1)](#ctor-16.1)
|
||||
|
||||
is_same_v<remove_cvref_t<U>, U> is true,
|
||||
|
||||
- [(16.2)](#ctor-16.2)
|
||||
|
||||
derived_from<U, T> is true,
|
||||
|
||||
- [(16.3)](#ctor-16.3)
|
||||
|
||||
is_constructible_v<U, Ts...> is true,
|
||||
|
||||
- [(16.4)](#ctor-16.4)
|
||||
|
||||
is_copy_constructible_v<U> is true, and
|
||||
|
||||
- [(16.5)](#ctor-16.5)
|
||||
|
||||
is_default_constructible_v<Allocator> is true[.](#ctor-16.sentence-1)
|
||||
|
||||
[17](#ctor-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*[.](#ctor-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](#ctor-18)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7128)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(18.1)](#ctor-18.1)
|
||||
|
||||
is_same_v<remove_cvref_t<U>, U> is true,
|
||||
|
||||
- [(18.2)](#ctor-18.2)
|
||||
|
||||
derived_from<U, T> is true,
|
||||
|
||||
- [(18.3)](#ctor-18.3)
|
||||
|
||||
is_constructible_v<U, Ts...> is true, and
|
||||
|
||||
- [(18.4)](#ctor-18.4)
|
||||
|
||||
is_copy_constructible_v<U> is true[.](#ctor-18.sentence-1)
|
||||
|
||||
[19](#ctor-19)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7141)
|
||||
|
||||
*Effects*: *alloc* is direct-non-list-initialized with a[.](#ctor-19.sentence-1)
|
||||
|
||||
Constructs an owned object of type U withstd::forward<Ts>(ts)... using the allocator *alloc*[.](#ctor-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](#ctor-20)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7156)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(20.1)](#ctor-20.1)
|
||||
|
||||
is_same_v<remove_cvref_t<U>, U> is true,
|
||||
|
||||
- [(20.2)](#ctor-20.2)
|
||||
|
||||
derived_from<U, T> is true,
|
||||
|
||||
- [(20.3)](#ctor-20.3)
|
||||
|
||||
is_constructible_v<U, initializer_list<I>&, Us...> is true,
|
||||
|
||||
- [(20.4)](#ctor-20.4)
|
||||
|
||||
is_copy_constructible_v<U> is true, and
|
||||
|
||||
- [(20.5)](#ctor-20.5)
|
||||
|
||||
is_default_constructible_v<Allocator> is true[.](#ctor-20.sentence-1)
|
||||
|
||||
[21](#ctor-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*[.](#ctor-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](#ctor-22)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7186)
|
||||
|
||||
*Constraints*:
|
||||
|
||||
- [(22.1)](#ctor-22.1)
|
||||
|
||||
is_same_v<remove_cvref_t<U>, U> is true,
|
||||
|
||||
- [(22.2)](#ctor-22.2)
|
||||
|
||||
derived_from<U, T> is true,
|
||||
|
||||
- [(22.3)](#ctor-22.3)
|
||||
|
||||
is_constructible_v<U, initializer_list<I>&, Us...> is true, and
|
||||
|
||||
- [(22.4)](#ctor-22.4)
|
||||
|
||||
is_copy_constructible_v<U> is true[.](#ctor-22.sentence-1)
|
||||
|
||||
[23](#ctor-23)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7200)
|
||||
|
||||
*Effects*: *alloc* is direct-non-list-initialized with a[.](#ctor-23.sentence-1)
|
||||
|
||||
Constructs an owned object of type U with the argumentsilist, std::forward<Us>(us)... using the allocator *alloc*[.](#ctor-23.sentence-2)
|
||||
|
||||
#### [20.4.2.4](#dtor) Destructor [[polymorphic.dtor]](polymorphic.dtor)
|
||||
|
||||
[ð](#lib:polymorphic,destructor)
|
||||
|
||||
`constexpr ~polymorphic();
|
||||
`
|
||||
|
||||
[1](#dtor-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7216)
|
||||
|
||||
*Mandates*: T is a complete type[.](#dtor-1.sentence-1)
|
||||
|
||||
[2](#dtor-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[.](#dtor-2.sentence-1)
|
||||
|
||||
#### [20.4.2.5](#assign) Assignment [[polymorphic.assign]](polymorphic.assign)
|
||||
|
||||
[ð](#lib:operator=,polymorphic)
|
||||
|
||||
`constexpr polymorphic& operator=(const polymorphic& other);
|
||||
`
|
||||
|
||||
[1](#assign-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7236)
|
||||
|
||||
*Mandates*: T is a complete type[.](#assign-1.sentence-1)
|
||||
|
||||
[2](#assign-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7240)
|
||||
|
||||
*Effects*: If addressof(other) == this is true, there are no effects[.](#assign-2.sentence-1)
|
||||
|
||||
Otherwise:
|
||||
|
||||
- [(2.1)](#assign-2.1)
|
||||
|
||||
The allocator needs updating ifallocator_traits<Allocator>::propagate_on_container_copy_assignment::value is true[.](#assign-2.1.sentence-1)
|
||||
|
||||
- [(2.2)](#assign-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[.](#assign-2.2.sentence-1)
|
||||
|
||||
- [(2.3)](#assign-2.3)
|
||||
|
||||
The previously owned object in *this, if any,
|
||||
is destroyed using allocator_traits<Allocator>::
|
||||
destroy and
|
||||
then the storage is deallocated[.](#assign-2.3.sentence-1)
|
||||
|
||||
- [(2.4)](#assign-2.4)
|
||||
|
||||
If the allocator needs updating,
|
||||
the allocator in *this is replaced with
|
||||
a copy of the allocator in other[.](#assign-2.4.sentence-1)
|
||||
|
||||
[3](#assign-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7272)
|
||||
|
||||
*Returns*: A reference to *this[.](#assign-3.sentence-1)
|
||||
|
||||
[4](#assign-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7276)
|
||||
|
||||
*Remarks*: If any exception is thrown, there are no effects on *this[.](#assign-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](#assign-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[.](#assign-5.sentence-1)
|
||||
|
||||
[6](#assign-6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7294)
|
||||
|
||||
*Effects*: If addressof(other) == this is true, there are no effects[.](#assign-6.sentence-1)
|
||||
|
||||
Otherwise:
|
||||
|
||||
- [(6.1)](#assign-6.1)
|
||||
|
||||
The allocator needs updating ifallocator_traits<Allocator>::propagate_on_container_move_assignment::value is true[.](#assign-6.1.sentence-1)
|
||||
|
||||
- [(6.2)](#assign-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[.](#assign-6.2.sentence-1)
|
||||
|
||||
- [(6.3)](#assign-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[.](#assign-6.3.sentence-1)
|
||||
|
||||
- [(6.4)](#assign-6.4)
|
||||
|
||||
The previously owned object in *this, if any,
|
||||
is destroyed using allocator_traits<Allocator>::
|
||||
destroy and
|
||||
then the storage is deallocated[.](#assign-6.4.sentence-1)
|
||||
|
||||
- [(6.5)](#assign-6.5)
|
||||
|
||||
If the allocator needs updating,
|
||||
the allocator in *this is replaced with
|
||||
a copy of the allocator in other[.](#assign-6.5.sentence-1)
|
||||
|
||||
[7](#assign-7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7336)
|
||||
|
||||
*Returns*: A reference to *this[.](#assign-7.sentence-1)
|
||||
|
||||
[8](#assign-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[.](#assign-8.sentence-1)
|
||||
|
||||
#### [20.4.2.6](#obs) Observers [[polymorphic.obs]](polymorphic.obs)
|
||||
|
||||
[ð](#lib:operator*,polymorphic)
|
||||
|
||||
`constexpr const T& operator*() const noexcept;
|
||||
constexpr T& operator*() noexcept;
|
||||
`
|
||||
|
||||
[1](#obs-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7355)
|
||||
|
||||
*Preconditions*: *this is not valueless[.](#obs-1.sentence-1)
|
||||
|
||||
[2](#obs-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7359)
|
||||
|
||||
*Returns*: A reference to the owned object[.](#obs-2.sentence-1)
|
||||
|
||||
[ð](#lib:operator-%3e,polymorphic)
|
||||
|
||||
`constexpr const_pointer operator->() const noexcept;
|
||||
constexpr pointer operator->() noexcept;
|
||||
`
|
||||
|
||||
[3](#obs-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7371)
|
||||
|
||||
*Preconditions*: *this is not valueless[.](#obs-3.sentence-1)
|
||||
|
||||
[4](#obs-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7375)
|
||||
|
||||
*Returns*: A pointer to the owned object[.](#obs-4.sentence-1)
|
||||
|
||||
[ð](#lib:valueless_after_move,polymorphic)
|
||||
|
||||
`constexpr bool valueless_after_move() const noexcept;
|
||||
`
|
||||
|
||||
[5](#obs-5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7386)
|
||||
|
||||
*Returns*: true if *this is valueless, otherwise false[.](#obs-5.sentence-1)
|
||||
|
||||
[ð](#lib:get_allocator,polymorphic)
|
||||
|
||||
`constexpr allocator_type get_allocator() const noexcept;
|
||||
`
|
||||
|
||||
[6](#obs-6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7397)
|
||||
|
||||
*Returns*: *alloc*[.](#obs-6.sentence-1)
|
||||
|
||||
#### [20.4.2.7](#swap) Swap [[polymorphic.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](#swap-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[.](#swap-1.sentence-1)
|
||||
|
||||
Otherwise get_allocator() == other.
|
||||
get_allocator() is true[.](#swap-1.sentence-2)
|
||||
|
||||
[2](#swap-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[.](#swap-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.3 Swappable requirements")[.](#swap-2.sentence-2)
|
||||
|
||||
Otherwise,
|
||||
the allocators are not swapped[.](#swap-2.sentence-3)
|
||||
|
||||
[*Note [1](#swap-note-1)*:
|
||||
|
||||
Does not call swap on the owned objects directly[.](#swap-2.sentence-4)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[ð](#swap-itemdecl:2)
|
||||
|
||||
`constexpr void swap(polymorphic& lhs, polymorphic& rhs) noexcept(noexcept(lhs.swap(rhs)));
|
||||
`
|
||||
|
||||
[3](#swap-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7442)
|
||||
|
||||
*Effects*: Equivalent to lhs.swap(rhs)[.](#swap-3.sentence-1)
|
||||
Reference in New Issue
Block a user