summaryrefslogtreecommitdiff
path: root/include/mbgl/util
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-02-25 19:24:16 +0200
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-02-26 22:31:59 +0200
commit1399040087f9d0b6f2a836fc5e6468c938ebf99b (patch)
tree3c9dee83750aac491d01abab085f90391270882a /include/mbgl/util
parentff6c1426e8f5e31b40e567052b8ca9bd45c6f537 (diff)
downloadqtlocation-mapboxgl-1399040087f9d0b6f2a836fc5e6468c938ebf99b.tar.gz
[core] Move mbgl::Pass and mbgl::PassRefPtr to a separate header
Diffstat (limited to 'include/mbgl/util')
-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