mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Data Fields | Private Types | Private Member Functions | Static Private Member Functions | Friends
m::unsharable_shared_ptr< T > Struct Template Reference

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>

Inheritance diagram for m::unsharable_shared_ptr< T >:
[legend]
Collaboration diagram for m::unsharable_shared_ptr< T >:
[legend]

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_ptroperator= (const unsharable_shared_ptr &)=default
 
unsharable_shared_ptroperator= (unsharable_shared_ptr &&)=default
 
template<typename Y >
unsharable_shared_ptroperator= (const unsharable_shared_ptr< Y > &ptr)
 
template<typename Y >
unsharable_shared_ptroperator= (unsharable_shared_ptr< Y > &&ptr)
 
template<typename Y >
unsharable_shared_ptroperator= (const std::shared_ptr< Y > &)=delete
 
template<typename Y >
unsharable_shared_ptroperator= (std::shared_ptr< Y > &&)=delete
 
std::unique_ptr< Texclusive_shared_to_unique ()
 Converts (and thereby moves) the exclusively held object from this unsharable_shared_ptr to a std::unique_ptr.
 
Toperator-> ()
 STL member.
 

Data Fields

T ptr
 STL member.
 

Private Types

using deleter_func_type = void(*)(const void *)
 

‍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 the this was constructed/assigned from another unsharable_shared_ptr of a compatible type, e.g.


 

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 >)
 

Detailed Description

template<typename T>
struct m::unsharable_shared_ptr< T >

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.

Member Typedef Documentation

◆ deleter_func_type

template<typename T >
using m::unsharable_shared_ptr< T >::deleter_func_type = void(*)(const void*)
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 the this was constructed/assigned from another unsharable_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.

◆ super

template<typename T >
using m::unsharable_shared_ptr< T >::super = std::shared_ptr<T>

Definition at line 27 of file unsharable_shared_ptr.hpp.

Constructor & Destructor Documentation

◆ unsharable_shared_ptr() [1/9]

template<typename T >
template<typename Y >
m::unsharable_shared_ptr< T >::unsharable_shared_ptr ( Y *  ptr)
inlineexplicit

Definition at line 42 of file unsharable_shared_ptr.hpp.

◆ unsharable_shared_ptr() [2/9]

template<typename T >
m::unsharable_shared_ptr< T >::unsharable_shared_ptr ( )
inline

Definition at line 44 of file unsharable_shared_ptr.hpp.

◆ unsharable_shared_ptr() [3/9]

template<typename T >
m::unsharable_shared_ptr< T >::unsharable_shared_ptr ( std::nullptr_t  )
inlineexplicit

Definition at line 45 of file unsharable_shared_ptr.hpp.

◆ unsharable_shared_ptr() [4/9]

template<typename T >
m::unsharable_shared_ptr< T >::unsharable_shared_ptr ( const unsharable_shared_ptr< T > &  )
default

◆ unsharable_shared_ptr() [5/9]

template<typename T >
m::unsharable_shared_ptr< T >::unsharable_shared_ptr ( unsharable_shared_ptr< T > &&  )
default

◆ unsharable_shared_ptr() [6/9]

template<typename T >
template<typename Y >
m::unsharable_shared_ptr< T >::unsharable_shared_ptr ( const unsharable_shared_ptr< Y > &  ptr)
inline

Definition at line 51 of file unsharable_shared_ptr.hpp.

◆ unsharable_shared_ptr() [7/9]

template<typename T >
template<typename Y >
m::unsharable_shared_ptr< T >::unsharable_shared_ptr ( unsharable_shared_ptr< Y > &&  ptr)
inline

Definition at line 53 of file unsharable_shared_ptr.hpp.

◆ unsharable_shared_ptr() [8/9]

template<typename T >
template<typename Y >
m::unsharable_shared_ptr< T >::unsharable_shared_ptr ( const std::shared_ptr< Y > &  )
delete

◆ unsharable_shared_ptr() [9/9]

template<typename T >
template<typename Y >
m::unsharable_shared_ptr< T >::unsharable_shared_ptr ( std::shared_ptr< Y > &&  ptr)
inlineprivate

Definition at line 61 of file unsharable_shared_ptr.hpp.

Member Function Documentation

◆ default_deleter()

template<typename T >
static void m::unsharable_shared_ptr< T >::default_deleter ( const void *  ptr)
inlinestaticprivate

Definition at line 37 of file unsharable_shared_ptr.hpp.

References m::T().

◆ exclusive_shared_to_unique()

template<typename T >
std::unique_ptr< T > m::unsharable_shared_ptr< T >::exclusive_shared_to_unique ( )
inline

Converts (and thereby moves) the exclusively held object from this unsharable_shared_ptr to a std::unique_ptr.

Returns
a std::unique_ptr owning the referenced object
Exceptions
`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().

◆ noop_deleter()

template<typename T >
static void m::unsharable_shared_ptr< T >::noop_deleter ( const void *  )
inlinestaticprivate

◆ operator->()

T* std::shared_ptr< T >::operator->
inherited

STL member.

◆ operator=() [1/6]

template<typename T >
template<typename Y >
unsharable_shared_ptr & m::unsharable_shared_ptr< T >::operator= ( const std::shared_ptr< Y > &  )
delete

◆ operator=() [2/6]

template<typename T >
unsharable_shared_ptr & m::unsharable_shared_ptr< T >::operator= ( const unsharable_shared_ptr< T > &  )
default

◆ operator=() [3/6]

template<typename T >
template<typename Y >
unsharable_shared_ptr & m::unsharable_shared_ptr< T >::operator= ( const unsharable_shared_ptr< Y > &  ptr)
inline

Definition at line 68 of file unsharable_shared_ptr.hpp.

◆ operator=() [4/6]

template<typename T >
template<typename Y >
unsharable_shared_ptr & m::unsharable_shared_ptr< T >::operator= ( std::shared_ptr< Y > &&  )
delete

◆ operator=() [5/6]

template<typename T >
unsharable_shared_ptr & m::unsharable_shared_ptr< T >::operator= ( unsharable_shared_ptr< T > &&  )
default

◆ operator=() [6/6]

template<typename T >
template<typename Y >
unsharable_shared_ptr & m::unsharable_shared_ptr< T >::operator= ( unsharable_shared_ptr< Y > &&  ptr)
inline

Definition at line 70 of file unsharable_shared_ptr.hpp.

Friends And Related Function Documentation

◆ as

template<typename T >
template<typename To , typename From >
unsharable_shared_ptr< To > as ( unsharable_shared_ptr< From >  )
friend

◆ cast

template<typename T >
template<typename To , typename From >
unsharable_shared_ptr< To > cast ( unsharable_shared_ptr< From >  )
friend

Field Documentation

◆ ptr

T std::shared_ptr< T >::ptr
inherited

STL member.


The documentation for this struct was generated from the following file: