The main constructor, accepting a pointer, is explicit:
my_ptr_type *p = ...;
MySharedPtr ptr = p; /* invalid */
MySharedPtr ptr{ p }; /* ok */
This prevents to mistakenly assign a pointer to a shared pointer.
However, assignment to nullptr should be acceptable:
MySharedPtr ptr = nullptr; /* should be ok */
Like unique_ptr, make the operator bool() explicit, so that it is only
called implicitly when the value may be "contextually converted to bool"
(if, while, etc.).
Suggested-by: Filip Roséen <filip@atch.se>
Signed-off-by: Thomas Guillem <thomas@gllm.fr>
Add a helper to create RAII wrappers for C shared resources, which
automatically call the Hold() and Release() functions associated to the
raw pointer.
Just declare a new shared resource wrapper type:
using InputItemPtr = vlc_shared_data_ptr_type(input_item_t,
input_item_Hold,
input_item_Release);
Then use this new type directly:
input_item_t *ptr = /* ... */;
InputItemPtr item(ptr);
QString name = item->psz_name;
InputItemPtr other = item; /* hold automatically */