cpp/experimental/optional/emplace: Difference between revisions
From cppreference.com
m Shorten template names. Use {{lc}} where appropriate. |
D41D8CD98F (talk | contribs) mNo edit summary |
||
| (7 intermediate revisions by 4 users not shown) | |||
| Line 1: | Line 1: | ||
{{cpp/ | {{cpp//optional/title|emplace}} | ||
{{cpp/ | {{cpp//optional/navbar}} | ||
{{dcl begin}} | {{dcl begin}} | ||
{{dcl | | {{dcl | =| 1= | ||
template< class... Args > | template< class... Args > | ||
void emplace( Args&&... args ); | void emplace( Args&&... args ); | ||
}} | }} | ||
{{dcl | | {{dcl | =| 1= | ||
template< class U, class... Args > | template< class U, class... Args > | ||
void emplace( std::initializer_list<U> ilist, Args&&... args ); | void emplace( std::initializer_list<U> ilist, Args&&... args ); | ||
| Line 12: | Line 12: | ||
{{dcl end}} | {{dcl end}} | ||
Constructs the contained value in-place. If {{c|*this}} | Constructs the contained value in-place. If {{c|*this}} before the call, the contained value is destroyed by calling its destructor. | ||
@1@ Initializes the contained value by | @1@ Initializes the contained value by with {{|args...}} as parameters. | ||
@2@ | @2@ the contained value by calling its constructor with {{|ilist}} {{|...}}. | ||
===Parameters=== | ===Parameters=== | ||
| Line 31: | Line 31: | ||
===Exceptions=== | ===Exceptions=== | ||
Any exception thrown by the selected constructor of {{tt|T}}. If an exception is thrown, {{c|*this}} | Any exception thrown by the selected constructor of {{tt|T}}. If an exception is thrown, {{c|*this}} after the . | ||
===See also=== | ===See also=== | ||
{{dsc begin}} | {{dsc begin}} | ||
{{dsc inc | cpp/ | {{dsc inc | cpp//optional/operator{{=}}}} | ||
{{dsc end}} | {{dsc end}} | ||
Latest revision as of 06:22, 16 May 2015
template< class... Args >
void emplace( Args&&... args );
|
(library fundamentals TS) | |
template< class U, class... Args >
void emplace( std::initializer_list<U> ilist, Args&&... args );
|
(library fundamentals TS) | |
Constructs the contained value in-place. If *this already contains a value before the call, the contained value is destroyed by calling its destructor.
1) Initializes the contained value by direct-initializing (but not direct-list-initializing) with
std::forward<Args>(args)... as parameters.2) Initializes the contained value by calling its constructor with
ilist, std::forward<Args>(args)... as parameters. This overload participates in overload resolution only if std::is_constructible<T, std::initializer_list<U>&, Args&&...>::value is true.Parameters
| args... | - | the arguments to pass to the constructor |
| ilist | - | the initializer list to pass to the constructor |
| Type requirements | ||
-T must be constructible from Args...
| ||
-T must be constructible from std::initializer_list and Args...
| ||
Return value
(none)
Exceptions
Any exception thrown by the selected constructor of T. If an exception is thrown, *this does not contain a value after this call (the previously contained value, if any, had been destroyed).
See also
| assigns contents (public member function) |