std::expected<T,E>::emplace
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Utilities library
Type support (basic types, RTTI)
Library feature-test macros (C++20)
(C++11)
(C++20)
(C++26)
(C++20)
Coroutine support (C++20)
Contract support (C++26)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)(C++20)
(C++20)(C++20)(C++20)
General utilities
Relational operators (deprecated in C++20)
(C++20)(C++20)(C++20)
(C++20)(C++20)(C++20)
(C++20)
Swap and type operations
Common vocabulary types
std::expected
expected::emplace
Primary template
template< class... Args >
constexpr T& emplace( Args&&... args ) noexcept;
(1)
(since C++23)
constexpr T& emplace( Args&&... args ) noexcept;
template< class U, class... Args >
constexpr T& emplace( std::initializer_list <U> il, Args&&... args ) noexcept;
(2)
(since C++23)
constexpr T& emplace( std::initializer_list <U> il, Args&&... args ) noexcept;
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
1) *std::construct_at (std::addressof (
val
), std::forward <Args>(args)...)2) *std::construct_at (std::addressof (
val
), il, std::forward <Args>(args)...)[edit] Notes
If the construction of T
is potentially-throwing, operator=
can be used instead.
[edit] Example
This section is incomplete
Reason: no example
Reason: no example