AK: Add Optional::value_or(T).

This is like value() but with a fallback in case there's no value set.
This commit is contained in:
Andreas Kling 2019-07-24 07:26:02 +02:00
parent 442256b5f8
commit adb7b1bc4c

View file

@ -96,6 +96,13 @@ public:
return released_value;
}
T value_or(const T& fallback) const
{
if (has_value())
return value();
return fallback;
}
private:
char m_storage[sizeof(T)] __attribute__((aligned(sizeof(T))));
bool m_has_value { false };