This is a generic scoped class for managing the lifetime of objects allocated on freestore.
More...
template<class T, class Dealloc = StandardArrayDelete<T>>
class Cgu::ScopedHandle< T, Dealloc >
This is a generic scoped class for managing the lifetime of objects allocated on freestore.
- See also
- SharedHandle SharedLockHandle SharedHandleError
-
StandardArrayDelete CFree GFree GerrorFree GSliceFree GSliceFreeSize GSliceDestroy
This class deletes its object as soon as it goes out of scope. It can be viewed as a SharedHandle which cannot be copy assigned to or used as the argument to a copy constructor and therefore which cannot have a reference count of more than 1.
ScopedHandle objects can be instantiated for pointers to constant objects (such as ScopedHandle<const char*>), provided the deleter functor will take such pointers.
This library provides StandardArrayDelete, CFree, GFree, GerrorFree, GSliceFree, GSliceFreeSize and GSliceDestroy deleter functors, which can be used as the second template parameter of the ScopedHandle class. StandardArrayDelete is the default, and some typedef'ed instances of ScopedHandle for gchar (with the GFree deleter) and for GError (with the GerrorFree deleter) are provided: GcharScopedHandle and GerrorScopedHandle)
Comparison with std::unique_ptr
This class is mainly retained to retain compatibility with series 1.2 of the library, since most of the things that can be done with it can also be done using std::unique_ptr. However, this class is a little easier to use when managing objects with associated C functions (such as in glib), because it provides a type conversion operator.
From version 2.0.19, this class has a move constructor and move assignment operator. Prior to that, it could not be moved from or to.