cancel: Add cancelable utility
This adds a common paradigm for handling a task that may need to be
canceled.
Change-Id: I2d06318f56788045f2688da137698dd7177e1fa2
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/meson.build b/src/meson.build
index dc4e02f..11bebe7 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -96,6 +96,7 @@
requires: stdplus_reqs)
install_headers(
+ 'stdplus/cancel.hpp',
'stdplus/exception.hpp',
'stdplus/flags.hpp',
'stdplus/raw.hpp',
diff --git a/src/stdplus/cancel.hpp b/src/stdplus/cancel.hpp
new file mode 100644
index 0000000..a6bf05b
--- /dev/null
+++ b/src/stdplus/cancel.hpp
@@ -0,0 +1,21 @@
+#pragma once
+#include <stdplus/handle/managed.hpp>
+
+namespace stdplus
+{
+
+struct Cancelable
+{
+ virtual ~Cancelable() = default;
+ virtual void cancel() noexcept = 0;
+};
+struct CancelableF
+{
+ inline void operator()(Cancelable* c) noexcept
+ {
+ c->cancel();
+ }
+};
+using Cancel = stdplus::Managed<Cancelable*>::HandleF<CancelableF>;
+
+} // namespace stdplus