|
|
@@ -96,67 +96,4 @@ namespace pkpy{
|
|
|
new(p+1) T(std::forward<Args>(args)...);
|
|
|
return shared_ptr<T>(p);
|
|
|
}
|
|
|
-
|
|
|
- template <typename T>
|
|
|
- class unique_ptr {
|
|
|
- T* ptr;
|
|
|
-
|
|
|
- public:
|
|
|
- unique_ptr() : ptr(nullptr) {}
|
|
|
- unique_ptr(T* ptr) : ptr(ptr) {}
|
|
|
- unique_ptr(const unique_ptr& other) = delete;
|
|
|
- unique_ptr(unique_ptr&& other) : ptr(other.ptr) {
|
|
|
- other.ptr = nullptr;
|
|
|
- }
|
|
|
- ~unique_ptr() {
|
|
|
- delete ptr;
|
|
|
- }
|
|
|
-
|
|
|
- bool operator==(const unique_ptr& other) const {
|
|
|
- return ptr == other.ptr;
|
|
|
- }
|
|
|
-
|
|
|
- bool operator!=(const unique_ptr& other) const {
|
|
|
- return ptr != other.ptr;
|
|
|
- }
|
|
|
-
|
|
|
- bool operator==(std::nullptr_t) const {
|
|
|
- return ptr == nullptr;
|
|
|
- }
|
|
|
-
|
|
|
- bool operator!=(std::nullptr_t) const {
|
|
|
- return ptr != nullptr;
|
|
|
- }
|
|
|
-
|
|
|
- unique_ptr& operator=(const unique_ptr& other) = delete;
|
|
|
-
|
|
|
- unique_ptr& operator=(unique_ptr&& other) {
|
|
|
- if (this != &other) {
|
|
|
- delete ptr;
|
|
|
- ptr = other.ptr;
|
|
|
- other.ptr = nullptr;
|
|
|
- }
|
|
|
- return *this;
|
|
|
- }
|
|
|
-
|
|
|
- T& operator*() const {
|
|
|
- return *ptr;
|
|
|
- }
|
|
|
- T* operator->() const {
|
|
|
- return ptr;
|
|
|
- }
|
|
|
- T* get() const {
|
|
|
- return ptr;
|
|
|
- }
|
|
|
-
|
|
|
- void reset(){
|
|
|
- delete ptr;
|
|
|
- ptr = nullptr;
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- template <typename T, typename... Args>
|
|
|
- unique_ptr<T> make_unique(Args&&... args) {
|
|
|
- return unique_ptr<T>(new T(std::forward<Args>(args)...));
|
|
|
- }
|
|
|
};
|