+/** A value from another process
+ *
+ * This represents a value from another process:
+ *
+ * * constructor/destructor are disabled;
+ *
+ * * raw memory copy (std::memcpy) is used to copy Remote<T>;
+ *
+ * * raw memory comparison is used to compare them;
+ *
+ * * when T is a trivial type, Remote is convertible to a T.
+ *
+ * We currently only handle the case where the type has the same layout
+ * in the current process and in the target process: we don't handle
+ * cross-architecture (such as 32-bit/64-bit access).
+ */
+template<class T>
+class Remote {
+private:
+ // If we use a union, it won't work with abstract types:
+ char buffer[sizeof(T)];
+public:
+ // HACK, some code currently cast this to T* which is **not** legal.
+ void* data() { return buffer; }
+ const void* data() const { return buffer; }
+ constexpr std::size_t size() const { return sizeof(T); }
+ operator T() const {
+ static_assert(std::is_trivial<T>::value, "Cannot convert non trivial type");
+ T res;
+ std::memcpy(&res, buffer, sizeof(T));
+ return res;
+ }
+ Remote() {}
+ Remote(T const& x)
+ {
+ std::memcpy(&x, buffer, sizeof(T));
+ }
+ Remote& operator=(T const& x)
+ {
+ std::memcpy(&x, buffer, sizeof(T));
+ }
+};
+