diff options
author | Itamar <itamar8910@gmail.com> | 2021-05-08 12:22:57 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-08 18:10:56 +0200 |
commit | 1da0d402b7f3476b30d7482ba63d8ad5d215dd96 (patch) | |
tree | fa35f2a8cb9c482a1b043003b5010e4311cccb6b /AK/Optional.h | |
parent | 484823e9d524ae0030552d02debdffbb14fa7f7e (diff) | |
download | serenity-1da0d402b7f3476b30d7482ba63d8ad5d215dd96.zip |
AK: Add constructors to Optional that accept non const qualified inputs
Diffstat (limited to 'AK/Optional.h')
-rw-r--r-- | AK/Optional.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/AK/Optional.h b/AK/Optional.h index 2d939ce099..9a1b786da8 100644 --- a/AK/Optional.h +++ b/AK/Optional.h @@ -56,6 +56,21 @@ public: } } + ALWAYS_INLINE Optional(Optional& other) + : m_has_value(other.m_has_value) + { + if (m_has_value) { + new (&m_storage) T(other.value()); + } + } + + template<typename U> + ALWAYS_INLINE Optional(U& value) + : m_has_value(true) + { + new (&m_storage) T(value); + } + ALWAYS_INLINE Optional& operator=(const Optional& other) { if (this != &other) { |