summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWilliam A. Kennington III <wak@google.com>2019-07-01 17:28:32 -0700
committerWilliam A. Kennington III <wak@google.com>2019-07-08 16:26:42 -0700
commit079cba7212a9a2e5eb7260492696675d67979346 (patch)
treef0e0c292fd67ee96883f76b004a26fa66f86657d /src
parentcbaeb1a38314cb92bfa487659ae9225e28421091 (diff)
downloadstdplus-079cba7212a9a2e5eb7260492696675d67979346.tar.gz
stdplus-079cba7212a9a2e5eb7260492696675d67979346.zip
handle: Support for releasing management of values
Sometimes we want to be able to break the value out of the container and unmanage it. Change-Id: I1ded8571561760f7adf8bbf9a24cf21c989e4898 Signed-off-by: William A. Kennington III <wak@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/stdplus/handle/managed.hpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/stdplus/handle/managed.hpp b/src/stdplus/handle/managed.hpp
index 9b9bfb5..de6a9f1 100644
--- a/src/stdplus/handle/managed.hpp
+++ b/src/stdplus/handle/managed.hpp
@@ -161,6 +161,31 @@ struct Managed
reset(std::nullopt);
}
+ /** @brief Releases the managed value and transfers ownership
+ * to the caller.
+ *
+ * @throws std::bad_optional_access if it has no object
+ * @return The value that was managed
+ */
+ [[nodiscard]] constexpr T release()
+ {
+ T ret = std::move(maybeT.value());
+ maybeT = std::nullopt;
+ return ret;
+ }
+
+ /** @brief Releases the managed value and transfers ownership
+ * to the caller.
+ *
+ * @return Maybe the value that was managed
+ */
+ [[nodiscard]] constexpr std::optional<T> maybe_release() noexcept
+ {
+ std::optional<T> ret = std::move(maybeT);
+ maybeT = std::nullopt;
+ return ret;
+ }
+
/** @brief Reference the contained data
*
* @return A reference to the contained data
OpenPOWER on IntegriCloud