mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:07:35 +00:00
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:
parent
442256b5f8
commit
adb7b1bc4c
1 changed files with 7 additions and 0 deletions
|
@ -96,6 +96,13 @@ public:
|
||||||
return released_value;
|
return released_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
T value_or(const T& fallback) const
|
||||||
|
{
|
||||||
|
if (has_value())
|
||||||
|
return value();
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char m_storage[sizeof(T)] __attribute__((aligned(sizeof(T))));
|
char m_storage[sizeof(T)] __attribute__((aligned(sizeof(T))));
|
||||||
bool m_has_value { false };
|
bool m_has_value { false };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue