template struct uptr { uptr() = default; uptr(Type* ptr) : ptr(ptr) { } ~uptr() { delete ptr; } // Take ownership of a raw pointer uptr& operator = (Type* in_ptr) { assert(ptr == nullptr); // Cast away constness for assignments. Not ideal but the language is limited, here. const_cast(ptr) = in_ptr; return *this; } // Non copyable uptr(const uptr&) = delete; uptr& operator = (const uptr&) = delete; // Move constructable, for return values uptr(uptr&& rhs) : ptr(rhs.ptr) { } // Disable move assignment, for now uptr& operator = (uptr&&) = delete; // Variable itself is const to discourage users from modifying it. It's public and not wrapped by // method access to prevent a tonne of generated code in debug and pointless stepping in/out of // functions when retrieving the pointer. Type* const ptr = nullptr; };