Page MenuHomePhorge

No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None
diff --git a/src/doc-interfaces/promise.hpp b/src/doc-interfaces/promise.hpp
new file mode 100644
index 0000000..cac65e5
--- /dev/null
+++ b/src/doc-interfaces/promise.hpp
@@ -0,0 +1,44 @@
+/*
+ * This file is part of libkazv.
+ * SPDX-FileCopyrightText: 2021 Tusooa Zhu <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#pragma once
+
+static_assert(false, "This is an *interface*, not an actual class in the library.");
+
+/**
+ * A Promise represents an asynchronous result that can be fetched later.
+ *
+ * @warning This is an *interface*, not an actual class in the library.
+ *
+ * A Promise is called *resolved* when the result becomes available.
+ *
+ * In libkazv docs, the result type is usually EffectStatus.
+ */
+template<class T>
+class Promise
+{
+public:
+ /**
+ * The type of the value this Promise will hold.
+ */
+ using DataT = T;
+
+ /**
+ * Specify something to do after this Promise resolves.
+ *
+ * @param f the function to run. It should take a DataT as the only argument.
+ *
+ * @return A Promise.
+ * Assume `result` is the result this Promise resolves to.
+ * If `f(result)` returns void, it resolves to `DataT()` after `f` returns.
+ * If `f(result)` returns a Promise, it resolves to what the Promise will resolve to,
+ * after that Promise resolves.
+ * Otherwise it resolves to what `f(result)` returns, implicitly converted to `DataT`,
+ * after that function returns.
+ */
+ template<class Func>
+ Promise then(Func &&f);
+};
diff --git a/src/doc-interfaces/range-t.hpp b/src/doc-interfaces/range-t.hpp
new file mode 100644
index 0000000..a7de711
--- /dev/null
+++ b/src/doc-interfaces/range-t.hpp
@@ -0,0 +1,50 @@
+/*
+ * This file is part of libkazv.
+ * SPDX-FileCopyrightText: 2021 Tusooa Zhu <tusooa@kazv.moe>
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+#pragma once
+
+static_assert(false, "This is an *interface*, not an actual class in the library.");
+
+#include <cstddef>
+
+/**
+ * A RangeT is an ordered collection that can be iterated through.
+ *
+ * @warning This is an *interface*, not an actual class in the library.
+ *
+ */
+template<class T>
+class RangeT
+{
+public:
+ /// The type of items in this range.
+ using DataT = T;
+
+ /**
+ * The beginning iterator of this range.
+ */
+ auto begin() const;
+
+ /**
+ * The past-end iterator of this range.
+ */
+ auto end() const;
+
+ /**
+ * Get the item at index with bound-checking.
+ *
+ * If there is no such index, it will throw.
+ */
+ const DataT &at(std::size_t index) const;
+
+ /**
+ * Get the item at index without bound-checking.
+ *
+ * If there is no such index, it might return a default-constructed
+ * instance, or it might be undefined behaviour.
+ */
+ const DataT &operator[](std::size_t index) const;
+};

File Metadata

Mime Type
text/x-diff
Expires
Sun, Oct 11, 10:16 AM (1 d, 16 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1785724
Default Alt Text
(2 KB)

Event Timeline