mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +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
Notes:
sideshowbarker
2024-07-17 03:25:49 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/96b36203a2 Pull-request: https://github.com/SerenityOS/serenity/pull/16396 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/awesomekling ✅
1 changed files with 8 additions and 0 deletions
|
@ -200,6 +200,14 @@ public:
|
|||
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 T& value() &
|
||||
|
|
Loading…
Reference in a new issue