[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​::​allocate orallocator_traits​::​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 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 is true, and - [(4.2)](#4.2) is_copy_constructible_v 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 is true, and - [(6.2)](#6.2) is_copy_constructible_v 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​::​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::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 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, - [(12.1)](#12.1) is_same_v is false, - [(12.2)](#12.2) derived_from is true, - [(12.3)](#12.3) is_constructible_v is true, - [(12.4)](#12.4) is_copy_constructible_v 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 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) using the allocator *alloc*[.](#13.sentence-1) [🔗](#lib:polymorphic,constructor______) `template 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, - [(14.1)](#14.1) is_same_v is false, - [(14.2)](#14.2) derived_from is true, - [(14.3)](#14.3) is_constructible_v is true, - [(14.4)](#14.4) is_copy_constructible_v 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) using the allocator *alloc*[.](#15.sentence-2) [🔗](#lib:polymorphic,constructor_______) `template constexpr explicit polymorphic(in_place_type_t, Ts&&... ts); ` [16](#16) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7098) *Constraints*: - [(16.1)](#16.1) is_same_v, U> is true, - [(16.2)](#16.2) derived_from is true, - [(16.3)](#16.3) is_constructible_v is true, - [(16.4)](#16.4) is_copy_constructible_v is true, and - [(16.5)](#16.5) is_default_constructible_v 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)... using the allocator *alloc*[.](#17.sentence-1) [🔗](#lib:polymorphic,constructor________) `template constexpr explicit polymorphic(allocator_arg_t, const Allocator& a, in_place_type_t, Ts&&... ts); ` [18](#18) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7128) *Constraints*: - [(18.1)](#18.1) is_same_v, U> is true, - [(18.2)](#18.2) derived_from is true, - [(18.3)](#18.3) is_constructible_v is true, and - [(18.4)](#18.4) is_copy_constructible_v 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)... using the allocator *alloc*[.](#19.sentence-2) [🔗](#lib:polymorphic,constructor_________) `template constexpr explicit polymorphic(in_place_type_t, initializer_list ilist, Us&&... us); ` [20](#20) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7156) *Constraints*: - [(20.1)](#20.1) is_same_v, U> is true, - [(20.2)](#20.2) derived_from is true, - [(20.3)](#20.3) is_constructible_v&, Us...> is true, - [(20.4)](#20.4) is_copy_constructible_v is true, and - [(20.5)](#20.5) is_default_constructible_v 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)... using the allocator *alloc*[.](#21.sentence-1) [🔗](#lib:polymorphic,constructor__________) `template constexpr explicit polymorphic(allocator_arg_t, const Allocator& a, in_place_type_t, initializer_list ilist, Us&&... us); ` [22](#22) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L7186) *Constraints*: - [(22.1)](#22.1) is_same_v, U> is true, - [(22.2)](#22.2) derived_from is true, - [(22.3)](#22.3) is_constructible_v&, Us...> is true, and - [(22.4)](#22.4) is_copy_constructible_v 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)... using the allocator *alloc*[.](#23.sentence-2)