Skip to content

Instantly share code, notes, and snippets.

@routevegetable
Last active July 11, 2022 16:45
Show Gist options
  • Save routevegetable/8e036c2dc061bbee9cd1b681617c2067 to your computer and use it in GitHub Desktop.
Save routevegetable/8e036c2dc061bbee9cd1b681617c2067 to your computer and use it in GitHub Desktop.
template<class T>
struct PolyBox {
typedef std::unique_ptr<T> Ptr;
/* Regular constructor */
PolyBox(Ptr&& p): ptr(std::move(p)) {}
/* Copy */
PolyBox(const PolyBox& t) : ptr(Ptr(t.ptr->clone())) {}
PolyBox& operator=(const PolyBox& t) {
ptr = Ptr(t.ptr->clone());
return *this;
}
/* Move */
PolyBox(PolyBox&& t) : ptr(std::move(t.ptr)) {}
PolyBox& operator=(PolyBox&& t) {
ptr = std::move(t.ptr);
return *this;
}
T& inner() {
return *ptr;
}
private:
Ptr ptr;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment