mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:17:34 +00:00
AK: Add Optional::emplace method.
This commit is contained in:
parent
b2de1ba779
commit
deb85c47b5
1 changed files with 13 additions and 4 deletions
|
@ -34,7 +34,8 @@
|
|||
namespace AK {
|
||||
|
||||
template<typename T>
|
||||
class alignas(T) [[nodiscard]] Optional {
|
||||
class alignas(T) [[nodiscard]] Optional
|
||||
{
|
||||
public:
|
||||
Optional() { }
|
||||
|
||||
|
@ -116,6 +117,14 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
template<typename... Parameters>
|
||||
ALWAYS_INLINE void emplace(Parameters && ... parameters)
|
||||
{
|
||||
clear();
|
||||
m_has_value = true;
|
||||
new (&m_storage) T(forward<Parameters>(parameters)...);
|
||||
}
|
||||
|
||||
ALWAYS_INLINE bool has_value() const { return m_has_value; }
|
||||
|
||||
ALWAYS_INLINE T& value()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue