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/test/cancel.cpp b/test/cancel.cpp
new file mode 100644
index 0000000..82da693
--- /dev/null
+++ b/test/cancel.cpp
@@ -0,0 +1,28 @@
+#include <stdplus/cancel.hpp>
+
+#include <gtest/gtest.h>
+
+namespace stdplus
+{
+
+struct FakeCancelable : public Cancelable
+{
+ size_t count = 0;
+ void cancel() noexcept override
+ {
+ count++;
+ }
+};
+
+TEST(CancelTest, Cancel)
+{
+ FakeCancelable c;
+ EXPECT_EQ(c.count, 0);
+ {
+ Cancel cancel(&c);
+ EXPECT_EQ(c.count, 0);
+ }
+ EXPECT_EQ(c.count, 1);
+}
+
+} // namespace stdplus