AK: Add Optional::emplace method.

This commit is contained in:
asynts 2020-08-29 19:18:01 +02:00 committed by Andreas Kling
commit deb85c47b5
Notes: sideshowbarker 2024-07-19 03:01:45 +09:00

View file

@ -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()