diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-07-24 07:26:02 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-07-24 07:26:02 +0200 |
commit | adb7b1bc4cc1911d02e19d785222f86e21a37bf0 (patch) | |
tree | 4661465ccbad7d7894b715a40d4eca0a6ed337a2 /AK | |
parent | 442256b5f858740fc935988d502a25385e9e2875 (diff) | |
download | serenity-adb7b1bc4cc1911d02e19d785222f86e21a37bf0.zip |
AK: Add Optional::value_or(T).
This is like value() but with a fallback in case there's no value set.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/Optional.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/AK/Optional.h b/AK/Optional.h index 7399b2ee4b..9dbef306fb 100644 --- a/AK/Optional.h +++ b/AK/Optional.h @@ -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 }; |