Last active
July 11, 2022 16:45
-
-
Save routevegetable/8e036c2dc061bbee9cd1b681617c2067 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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