-template<typename T>
-class NodePtr
-{
-private:
- T *node;
-
-public:
- NodePtr(T *n = 0): node(n) { }
- NodePtr(const NodePtr &p): node(clone(p.node)) { }
- NodePtr &operator=(const NodePtr &p) { delete node; node = clone(p.node); return *this; }
-#if __cplusplus>=201103L
- NodePtr(NodePtr &&p): node(p.node) { p.node = 0; }
- NodePtr &operator=(NodePtr &&p) { delete node; node = p.node; p.node = 0; return *this; }
-#endif
- ~NodePtr() { delete node; }
-
-private:
- static T *clone(T *n) { return n ? n->clone() : 0; }
-
-public:
- T *operator->() { return node; }
- const T *operator->() const { return node; }
- T &operator*() { return *node; }
- const T &operator*() const { return *node; }
- operator void *() const { return node; }
-};
-