summaryrefslogtreecommitdiff
path: root/include/mbgl/util/pass_types.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/mbgl/util/pass_types.hpp')
-rw-r--r--include/mbgl/util/pass_types.hpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/include/mbgl/util/pass_types.hpp b/include/mbgl/util/pass_types.hpp
new file mode 100644
index 0000000000..5415a3177f
--- /dev/null
+++ b/include/mbgl/util/pass_types.hpp
@@ -0,0 +1,24 @@
+#pragma once
+
+#include <memory>
+
+namespace mbgl {
+
+// Using this type as a return type enforces the client to retain the returned object.
+template <typename T>
+class Pass {
+public:
+ Pass(T&& obj_) : obj(std::forward<T>(obj_)) {}
+ Pass(Pass&&) noexcept = default;
+ Pass(const Pass&) = delete;
+ Pass& operator=(const Pass&) = delete;
+ operator T() && { return std::move(obj); }
+
+private:
+ T obj;
+};
+
+template <typename T>
+using PassRefPtr = Pass<std::shared_ptr<T>>;
+
+} // namespace mbgl \ No newline at end of file