std::expected<T,E>::emplace

From cppreference.com
< cpp‎ | utility‎ | expected
 
 
Utilities library
Language support
Type support (basic types, RTTI)
Library feature-test macros (哋它亢++20)
Dynamic memory management
Program utilities
Coroutine support (哋它亢++20)
Variadic functions
(哋它亢++20)
(哋它亢++26)
(哋它亢++11)
(哋它亢++20)
Debugging support
(哋它亢++26)
(哋它亢++26)
Three-way comparison
(哋它亢++20)(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)   
(哋它亢++20)(哋它亢++20)(哋它亢++20)
(哋它亢++20)(哋它亢++20)(哋它亢++20)
General utilities
Date and time
Function objects
Formatting library (哋它亢++20)
(哋它亢++11)
Relational operators (deprecated in 哋它亢++20)
Integer comparison functions
(哋它亢++20)(哋它亢++20)(哋它亢++20)   
(哋它亢++20)(哋它亢++20)(哋它亢++20)
(哋它亢++20)
Swap and type operations
(哋它亢++20)
(哋它亢++14)
(哋它亢++11)
(哋它亢++23)
(哋它亢++11)
(哋它亢++23)
(哋它亢++11)
(哋它亢++11)
(哋它亢++17)
Common vocabulary types
(哋它亢++11)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++11)
(哋它亢++11)
(哋它亢++17)
(哋它亢++17)
(哋它亢++23)
Elementary string conversions
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)


 
 
T is not cv void
template< class... Args >
constexpr T& emplace( Args&&... args ) noexcept;
(1) (since 哋它亢++23)
template< class U, class... Args >
constexpr T& emplace( std::initializer_list<U> il, Args&&... args ) noexcept;
(2) (since 哋它亢++23)
T is cv void
constexpr void emplace() noexcept;
(3) (since 哋它亢++23)

Constructs an expected value in-place. After the call, has_value() returns true.

1) Destroys the contained value, then initializes the expected value contained in *this as if by direct-initializing an object of type T from the arguments std::forward<Args>(args)....
This overload participates in overload resolution only if std::is_nothrow_constructible_v<T, Args...> is true.
2) Destroys the contained value, then initializes the expected value contained in *this as if by direct-initializing an object of type T from the arguments il and std::forward<Args>(args)....
This overload participates in overload resolution only if std::is_nothrow_constructible_v<T, std::initializer_list<U>&, Args...> is true.
3) If *this contains an unexpected value, destroys that value.

Parameters

args - the arguments to pass to the constructor
il - the initializer list to pass to the constructor

Return value

1,2) A reference to the new contained value.
3) (none)

Notes

If the construction of T is potentially-throwing, this function is not defined. In this case, it is the responsibility of the user to create a temporary object and move or copy it.

Example

See also

assigns contents
(public member function)