mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:47:35 +00:00
AK: Add Optional::lazy_emplace(Callable)
This makes it possible to emplace using a given function instead of passing constructor arguments.
This commit is contained in:
parent
0ed9fe3864
commit
96b36203a2
1 changed files with 8 additions and 0 deletions
|
@ -200,6 +200,14 @@ public:
|
||||||
new (&m_storage) T(forward<Parameters>(parameters)...);
|
new (&m_storage) T(forward<Parameters>(parameters)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename Callable>
|
||||||
|
ALWAYS_INLINE void lazy_emplace(Callable callable)
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
m_has_value = true;
|
||||||
|
new (&m_storage) T { callable() };
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] ALWAYS_INLINE bool has_value() const { return m_has_value; }
|
[[nodiscard]] ALWAYS_INLINE bool has_value() const { return m_has_value; }
|
||||||
|
|
||||||
[[nodiscard]] ALWAYS_INLINE T& value() &
|
[[nodiscard]] ALWAYS_INLINE T& value() &
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue