35 #if !defined(_smart_ptr_h_) 44 static inline void del(T *v) {
delete v; }
51 static inline void del(T *v) { free(v); }
58 static inline void del(T *v) {
delete[] v; }
66 template <
typename T,
class delete_policy = smart_ptr_delete<T> >
72 typedef const T *const_ptr_type;
74 typedef const T &const_ref_type;
108 ptr_type
get() {
return _p; }
111 const_ptr_type
get()
const {
return _p; }
139 delete_policy::del(_p);
148 operator ptr_type() {
return _p; }
151 operator const_ptr_type()
const {
return _p; }
154 operator ref_type() {
return *_p; }
157 operator const_ref_type()
const {
return *_p; }
160 operator bool()
const {
return _p !=
nullptr; }
187 template <
typename T>
191 template <
typename T>
194 #endif // _smart_ptr_h_ const_ptr_type operator->() const
Another operator to allow you to treat the object just like a pointer.
Definition: smart_ptr.h:173
smart_ptr(smart_ptr< T > &&other)
Move copy constructor.
Definition: smart_ptr.h:89
void clear()
Dissociates a previously set pointer value, deleting it at the same time.
Definition: smart_ptr.h:130
Delete policy using free() to delete objects.
Definition: smart_ptr.h:49
ptr_type operator->()
Another operator to allow you to treat the object just like a pointer.
Definition: smart_ptr.h:170
ptr_type _p
The wrapped pointer.
Definition: smart_ptr.h:177
smart_ptr()
Default constructor. Initializes with no pointer set.
Definition: smart_ptr.h:77
Delete policy for arrays.
Definition: smart_ptr.h:56
Simple, standard smart pointer class.
Definition: smart_ptr.h:67
smart_ptr< T > & operator=(ptr_type p)
To allow setting the pointer directly. Equivalent to a call to set().
Definition: smart_ptr.h:163
virtual ~smart_ptr()
Definition: smart_ptr.h:105
smart_ptr< T > & operator=(smart_ptr< T > &&other)
Move assignment operator.
Definition: smart_ptr.h:96
Delete policy for regular objects.
Definition: smart_ptr.h:42
void reset()
Dissociates any previously set pointer value without deleting it.
Definition: smart_ptr.h:127
smart_ptr(ptr_type p)
This constructor takes a pointer to the object to be deleted.
Definition: smart_ptr.h:83
virtual void safe_delete()
Definition: smart_ptr.h:135