Namespaces
Variants
Actions

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

From cppreference.com
< cpp‎ | utility‎ | expected
 
C++
 
Utilities library
General utilities
Relational operators (deprecated in C++20)
 
std::expected
Primary template
template< class... Args >
constexpr T& emplace( Args&&... args ) noexcept;
(1) (since C++23)
template< class U, class... Args >
constexpr T& emplace( std::initializer_list<U> il, Args&&... args ) noexcept;
(2) (since C++23)
void partial specialization
constexpr void emplace() noexcept;
(3) (since C++23)

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

1) Destroys the contained value, then direct-initializes the expected value contained in *this with 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 direct-initializes the expected value contained in *this with 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.

Contents

[edit] Parameters

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

[edit] Return value

[edit] Notes

If the construction of T is potentially-throwing, operator= can be used instead.

[edit] Example

[edit] See also

assigns contents
(public member function) [edit]

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant