![]() |
mutable
A Database System for Research and Fast Prototyping
|
This class extends std::shared_ptr
to allow for unsharing an exclusively held object and thereby converting to a std::unique_ptr
.
More...
#include <unsharable_shared_ptr.hpp>
Public Types | |
using | super = std::shared_ptr< T > |
Public Member Functions | |
template<typename Y > | |
unsharable_shared_ptr (Y *ptr) | |
unsharable_shared_ptr () | |
unsharable_shared_ptr (std::nullptr_t) | |
unsharable_shared_ptr (const unsharable_shared_ptr &)=default | |
unsharable_shared_ptr (unsharable_shared_ptr &&)=default | |
template<typename Y > | |
unsharable_shared_ptr (const unsharable_shared_ptr< Y > &ptr) | |
template<typename Y > | |
unsharable_shared_ptr (unsharable_shared_ptr< Y > &&ptr) | |
template<typename Y > | |
unsharable_shared_ptr (const std::shared_ptr< Y > &)=delete | |
unsharable_shared_ptr & | operator= (const unsharable_shared_ptr &)=default |
unsharable_shared_ptr & | operator= (unsharable_shared_ptr &&)=default |
template<typename Y > | |
unsharable_shared_ptr & | operator= (const unsharable_shared_ptr< Y > &ptr) |
template<typename Y > | |
unsharable_shared_ptr & | operator= (unsharable_shared_ptr< Y > &&ptr) |
template<typename Y > | |
unsharable_shared_ptr & | operator= (const std::shared_ptr< Y > &)=delete |
template<typename Y > | |
unsharable_shared_ptr & | operator= (std::shared_ptr< Y > &&)=delete |
std::unique_ptr< T > | exclusive_shared_to_unique () |
Converts (and thereby moves) the exclusively held object from this unsharable_shared_ptr to a std::unique_ptr . | |
T * | operator-> () |
STL member. | |
Data Fields | |
T | ptr |
STL member. | |
Private Types | |
using | deleter_func_type = void(*)(const void *) |
| |
Private Member Functions | |
template<typename Y > | |
unsharable_shared_ptr (std::shared_ptr< Y > &&ptr) | |
Static Private Member Functions | |
static void | default_deleter (const void *ptr) |
static void | noop_deleter (const void *) |
Friends | |
template<typename To , typename From > | |
unsharable_shared_ptr< To > | cast (unsharable_shared_ptr< From >) |
template<typename To , typename From > | |
unsharable_shared_ptr< To > | as (unsharable_shared_ptr< From >) |
This class extends std::shared_ptr
to allow for unsharing an exclusively held object and thereby converting to a std::unique_ptr
.
Beware, that this class relies on accurate use_count()
. The use_count()
is inaccurate if the shared_ptr is shared across threads. Therefore, this class must not be used in a shared environment.
If support for multi-threading is needed, a wrapper around unsharable_shared_ptr
may be used together with a mutex to guard operations and synchronize on the use_count()
.
Definition at line 22 of file unsharable_shared_ptr.hpp.
|
private |
custom deleter type; use function pointer instead of reference due to clang-17 issue; use
const void*
as parameter type to enable accessing the custom deleter even if thethis
was constructed/assigned from anotherunsharable_shared_ptr
of a compatible type, e.g.
qualified without const
or a derived class
Definition at line 36 of file unsharable_shared_ptr.hpp.
using m::unsharable_shared_ptr< T >::super = std::shared_ptr<T> |
Definition at line 27 of file unsharable_shared_ptr.hpp.
|
inlineexplicit |
Definition at line 42 of file unsharable_shared_ptr.hpp.
|
inline |
Definition at line 44 of file unsharable_shared_ptr.hpp.
|
inlineexplicit |
Definition at line 45 of file unsharable_shared_ptr.hpp.
|
default |
|
default |
|
inline |
Definition at line 51 of file unsharable_shared_ptr.hpp.
|
inline |
Definition at line 53 of file unsharable_shared_ptr.hpp.
|
delete |
|
inlineprivate |
Definition at line 61 of file unsharable_shared_ptr.hpp.
|
inlinestaticprivate |
Definition at line 37 of file unsharable_shared_ptr.hpp.
References m::T().
|
inline |
Converts (and thereby moves) the exclusively held object from this unsharable_shared_ptr
to a std::unique_ptr
.
std::unique_ptr
owning the referenced object `std::logic_error` | if this unsharable_shared_ptr does not hold the referenced object exclusively |
Definition at line 84 of file unsharable_shared_ptr.hpp.
References M_insist, and m::unsharable_shared_ptr< T >::noop_deleter().
|
inlinestaticprivate |
Definition at line 38 of file unsharable_shared_ptr.hpp.
Referenced by m::unsharable_shared_ptr< T >::exclusive_shared_to_unique().
|
delete |
|
default |
|
inline |
Definition at line 68 of file unsharable_shared_ptr.hpp.
|
delete |
|
default |
|
inline |
Definition at line 70 of file unsharable_shared_ptr.hpp.
|
friend |
|
friend |