mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-29 16:21:29 +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
Notes:
sideshowbarker
2024-07-19 13:04:55 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/adb7b1bc4cc
|
@ -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 };
|
||||
|
|
Loading…
Reference in a new issue