[variant.mod] # 22 General utilities library [[utilities]](./#utilities) ## 22.6 Variants [[variant]](variant#mod) ### 22.6.3 Class template variant [[variant.variant]](variant.variant#variant.mod) #### 22.6.3.5 Modifiers [variant.mod] [🔗](#lib:emplace,variant) `template constexpr T& emplace(Args&&... args); ` [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6244) *Constraints*: is_constructible_v is true, andT occurs exactly once in Types[.](#1.sentence-1) [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6249) *Effects*: Equivalent to:return emplace(std::forward(args)...); where I is the zero-based index of T in Types[.](#2.sentence-1) [🔗](#lib:emplace,variant_) `template constexpr T& emplace(initializer_list il, Args&&... args); ` [3](#3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6265) *Constraints*: is_constructible_v&, Args...> is true, and T occurs exactly once in Types[.](#3.sentence-1) [4](#4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6270) *Effects*: Equivalent to:return emplace(il, std::forward(args)...); where I is the zero-based index of T in Types[.](#4.sentence-1) [🔗](#lib:emplace,variant__) `template constexpr variant_alternative_t>& emplace(Args&&... args); ` [5](#5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6286) *Mandates*: I < sizeof...(Types)[.](#5.sentence-1) [6](#6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6290) *Constraints*: is_constructible_v is true[.](#6.sentence-1) [7](#7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6294) *Effects*: Destroys the currently contained value if valueless_by_exception() is false[.](#7.sentence-1) Then direct-non-list-initializes the contained value of type TI with the arguments std​::​forward(args)...[.](#7.sentence-2) [8](#8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6301) *Postconditions*: index() is I[.](#8.sentence-1) [9](#9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6305) *Returns*: A reference to the new contained value[.](#9.sentence-1) [10](#10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6309) *Throws*: Any exception thrown during the initialization of the contained value[.](#10.sentence-1) [11](#11) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6313) *Remarks*: If an exception is thrown during the initialization of the contained value, the variant is permitted to not hold a value[.](#11.sentence-1) [🔗](#lib:emplace,variant___) `template constexpr variant_alternative_t>& emplace(initializer_list il, Args&&... args); ` [12](#12) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6327) *Mandates*: I < sizeof...(Types)[.](#12.sentence-1) [13](#13) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6331) *Constraints*: is_constructible_v&, Args...> is true[.](#13.sentence-1) [14](#14) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6335) *Effects*: Destroys the currently contained value if valueless_by_exception() is false[.](#14.sentence-1) Then direct-non-list-initializes the contained value of type TI with il, std​::​forward(args)...[.](#14.sentence-2) [15](#15) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6342) *Postconditions*: index() is I[.](#15.sentence-1) [16](#16) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6346) *Returns*: A reference to the new contained value[.](#16.sentence-1) [17](#17) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6350) *Throws*: Any exception thrown during the initialization of the contained value[.](#17.sentence-1) [18](#18) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L6354) *Remarks*: If an exception is thrown during the initialization of the contained value, the variant is permitted to not hold a value[.](#18.sentence-1)