diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-11-02 18:32:17 +0100 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-12-20 15:35:58 +0100 |
commit | be34f768e093cb6752ab81fde3ab529861a8a6a8 (patch) | |
tree | 284a6ca5a79fb2a647586e2bfdb11b3923e01f91 /asl/option.hpp | |
parent | afd8e711ab35e8d21bc9c8397f31dcf7ecdec2e3 (diff) |
Add emplace to option
Diffstat (limited to 'asl/option.hpp')
-rw-r--r-- | asl/option.hpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/asl/option.hpp b/asl/option.hpp index bb266ab..ab88992 100644 --- a/asl/option.hpp +++ b/asl/option.hpp @@ -387,6 +387,15 @@ public: {
return has_value() ? ASL_MOVE(value()) : static_cast<T>(ASL_FWD(other_value));
}
+
+ template<typename... Args>
+ T& emplace(Args&&... args) &
+ requires constructible<T, Args&&...>
+ {
+ if (m_has_value) { reset(); }
+ construct(ASL_FWD(args)...);
+ return value();
+ }
};
template<typename T>
|