diff options
author | Chris Robinson <[email protected]> | 2021-12-31 15:28:47 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2021-12-31 15:28:47 -0800 |
commit | ad9c2d77c8cc1a4169c908cbaef606aa7b0b2635 (patch) | |
tree | ace34b50527324dcd55770f6e9dd9c4b7e71af28 /common | |
parent | 2750571411cd6990ebea0fdb5038380e49a765a7 (diff) |
Add a couple more methods to al::optional
Diffstat (limited to 'common')
-rw-r--r-- | common/aloptional.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/common/aloptional.h b/common/aloptional.h index c83e1dc8..a1229413 100644 --- a/common/aloptional.h +++ b/common/aloptional.h @@ -315,6 +315,22 @@ public: constexpr T value_or(U&& defval) && { return bool{*this} ? std::move(**this) : static_cast<T>(std::forward<U>(defval)); } + template<typename ...Args> + constexpr T& emplace(Args&& ...args) + { + mStore.reset(); + mStore.construct(std::forward<Args>(args)...); + return mStore.mValue; + } + template<typename U, typename ...Args> + constexpr std::enable_if_t<std::is_constructible<T, std::initializer_list<U>&, Args&&...>::value, + T&> emplace(std::initializer_list<U> il, Args&& ...args) + { + mStore.reset(); + mStore.construct(il, std::forward<Args>(args)...); + return mStore.mValue; + } + constexpr void reset() noexcept { mStore.reset(); } }; |