libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT > Class Template Referencefinal

A unique pointer-type that has threading specified as a trait. More...

#include <unique_ptr.hpp>

Public Types

using value_type = V
 A convenience typedef to the type to be controlled. More...
 
using element_type = value_type
 A convenience typedef to the type to be controlled. More...
 
using lock_traits = LkT
 
using atomic_ptr_t = typename lock_traits::template atomic< value_type * >
 The (potentially) lock-free pointer type. More...
 
using deleter_t = typename value_type::deleter_t
 Make sure the correct object-deletion mechanism is used. More...
 
using no_deletion = noop_dtor< typename value_type::deleter_t::element_type >
 

Public Member Functions

atomic_ptr_t __fastcall release () noexcept(true) FORCE_INLINE
 
constexpr __stdcall unique_ptr () noexcept(true) FORCE_INLINE
 
constexpr __stdcall unique_ptr (value_type *ptr) noexcept(true) FORCE_INLINE
 
template<class V1 >
__stdcall FORCE_INLINE unique_ptr (V1 *ptr) noexcept(true)
 
__stdcall unique_ptr (atomic_ptr_t &&ptr) noexcept(true) FORCE_INLINE
 
template<class V1 , template< class > class At>
__stdcall FORCE_INLINE unique_ptr (At< V1 * > &&ptr) noexcept(true)
 
constexpr __stdcall unique_ptr (std::unique_ptr< value_type, deleter_t > &&ptr) noexcept(true) FORCE_INLINE
 
template<class V1 >
__stdcall unique_ptr (std::unique_ptr< V1, typename V1::deleter_t > &&ptr) noexcept(true) FORCE_INLINE
 
template<class V2 , class LkT2 >
__stdcall FORCE_INLINE unique_ptr (unique_ptr< V2, LkT2 > &&s) noexcept(true)
 
constexpr unique_ptr (unique_ptr &&s) noexcept(true) FORCE_INLINE
 
__stdcall ~unique_ptr () noexcept(true) FORCE_INLINE
 
template<class V2 , class LkT2 >
void operator= (unique_ptr< V2, LkT2 > &&s) noexcept(true) FORCE_INLINE
 
void operator= (unique_ptr &&s) noexcept(true) FORCE_INLINE
 
void __fastcall reset () noexcept(true) FORCE_INLINE
 
constexpr bool __fastcall operator== (const unique_ptr &s) const noexcept(true) FORCE_INLINE
 
constexpr bool __fastcall operator!= (const unique_ptr &s) const noexcept(true) FORCE_INLINE
 
constexpr bool __fastcall operator< (const unique_ptr &s) const noexcept(true) FORCE_INLINE
 
constexpr bool __fastcall operator> (const unique_ptr &s) const noexcept(true) FORCE_INLINE
 
constexpr operator bool () const noexcept(true) FORCE_INLINE
 
constexpr const atomic_ptr_t &__fastcall get () const noexcept(true) FORCE_INLINE
 
atomic_ptr_t &__fastcall get () noexcept(true) FORCE_INLINE
 
constexpr const value_type &__fastcall operator* () const noexcept(true) FORCE_INLINE
 
value_type &__fastcall operator* () noexcept(true) FORCE_INLINE
 
constexpr value_type const *__fastcall operator-> () const noexcept(true) FORCE_INLINE
 
value_type *__fastcall operator-> () noexcept(true) FORCE_INLINE
 
void swap (unique_ptr &s) noexcept(true) FORCE_INLINE
 
template<class V1 >
__fastcall void FORCE_INLINE swap (unique_ptr< V1, LkT > &s) noexcept(true)
 
template<class V2 , class LkT2 >
__fastcall void FORCE_INLINE swap (unique_ptr< V2, LkT2 > &s) noexcept(true)
 
tstring to_string () const noexcept(false)
 
template<class V1 >
void swap (unique_ptr< V1, LkT > &s) noexcept(true)
 
template<class V2 , class LkT2 >
void swap (unique_ptr< V2, LkT2 > &s) noexcept(true)
 
template<class V1 >
 unique_ptr (V1 *ptr) noexcept(true)
 
template<class V1 , template< class > class At>
 unique_ptr (At< V1 * > &&ptr) noexcept(true)
 
template<class V1 >
 unique_ptr (std::unique_ptr< V1, typename V1::deleter_t > &&d) noexcept(true)
 
template<typename V2 , class LkT2 >
 unique_ptr (unique_ptr< V2, LkT2 > &&s) noexcept(true)
 

Static Public Attributes

static constexpr ppd::generic_traits::memory_access_modes memory_access_mode =atomic_ptr_t::memory_access_mode
 

Friends

template<class , class >
class unique_ptr
 
tostream &__fastcall operator<< (tostream &os, unique_ptr const &ptr) noexcept(false) FORCE_INLINE
 

Detailed Description

template<class V, class LkT>
class jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >

A unique pointer-type that has threading specified as a trait.

I don't use boost::scoped_ptr nor std::unique_ptr as they are insufficiently flexible for my purposes: the multi-threading model they use is not a trait, and the deleter is part of the type, which won't work in a container in the way I need. This class uses a lock-free implementation ultimately based upon std::atomic.

See also
boost::scoped_ptr, std::unique_ptr, libjmmcg::unique_ptr

Definition at line 38 of file unique_ptr.hpp.

Member Typedef Documentation

◆ atomic_ptr_t

template<class V , class LkT >
using jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::atomic_ptr_t = typename lock_traits::template atomic<value_type *>

The (potentially) lock-free pointer type.

We need the operations on the contained pointer (to the managed object) to be atomic because the move operations might occur on more than one thread, and therefore there is a race condition on non-SMP architectures, which is avoided if (in the implementation) the operations on the contained pointer are atomic.

Definition at line 47 of file unique_ptr.hpp.

◆ deleter_t

template<class V , class LkT >
using jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::deleter_t = typename value_type::deleter_t

Make sure the correct object-deletion mechanism is used.

Definition at line 49 of file unique_ptr.hpp.

◆ element_type

template<class V , class LkT >
using jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::element_type = value_type

A convenience typedef to the type to be controlled.

Definition at line 41 of file unique_ptr.hpp.

◆ lock_traits

template<class V , class LkT >
using jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::lock_traits = LkT

This does not have to be the same as the element_type, as it may not contain any lock_traits, or we may want the flexibility to deal with the type differently in this case.

Definition at line 42 of file unique_ptr.hpp.

◆ no_deletion

template<class V , class LkT >
using jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::no_deletion = noop_dtor<typename value_type::deleter_t::element_type>

If you get a compilation issue here, check you aren't using std::default_delete, but libjmmcg::default_delete instead.

See also
libjmmcg::default_delete

Definition at line 55 of file unique_ptr.hpp.

◆ value_type

template<class V , class LkT >
using jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::value_type = V

A convenience typedef to the type to be controlled.

Definition at line 40 of file unique_ptr.hpp.

Constructor & Destructor Documentation

◆ unique_ptr() [1/13]

template<class V , class LkT >
constexpr __stdcall jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::unique_ptr ( )
inlineconstexprnoexcept

Definition at line 67 of file unique_ptr.hpp.

◆ unique_ptr() [2/13]

template<class V , class LkT >
constexpr jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::unique_ptr ( value_type ptr)
inlineexplicitconstexprnoexcept
Parameters
ptrNote that this ptr could have a non-zero reference count, and this ctor will take ownership of the ptr, respecting that reference count, only deleting the ptr if it reaches zero.

Definition at line 56 of file unique_ptr_impl.hpp.

◆ unique_ptr() [3/13]

template<class V , class LkT >
template<class V1 >
__stdcall FORCE_INLINE jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::unique_ptr ( V1 *  ptr)
explicitnoexcept
Parameters
ptrNote that this ptr could have a non-zero reference count, and this ctor will take ownership of the ptr, respecting that reference count, only deleting the ptr if it reaches zero. The type of the parameter must be the same type or a class non-privately derived from value_type.

◆ unique_ptr() [4/13]

template<class V , class LkT >
jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::unique_ptr ( atomic_ptr_t &&  ptr)
inlineexplicitnoexcept
Parameters
ptrNote that this ptr could have a non-zero reference count, and this ctor will take ownership of the ptr, respecting that reference count, only deleting the ptr if it reaches zero.

Definition at line 69 of file unique_ptr_impl.hpp.

◆ unique_ptr() [5/13]

template<class V , class LkT >
template<class V1 , template< class > class At>
__stdcall FORCE_INLINE jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::unique_ptr ( At< V1 * > &&  ptr)
noexcept
Parameters
ptrNote that this ptr could have a non-zero reference count, and this ctor will take ownership of the ptr, respecting that reference count, only deleting the ptr if it reaches zero.

◆ unique_ptr() [6/13]

template<class V , class LkT >
constexpr jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::unique_ptr ( std::unique_ptr< value_type, deleter_t > &&  ptr)
inlineexplicitconstexprnoexcept
Parameters
ptrNote that this ptr could have a non-zero reference count, and this ctor will take ownership of the ptr, respecting that reference count, only deleting the ptr if it reaches zero.

Definition at line 89 of file unique_ptr_impl.hpp.

◆ unique_ptr() [7/13]

template<class V , class LkT >
template<class V1 >
__stdcall jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::unique_ptr ( std::unique_ptr< V1, typename V1::deleter_t > &&  ptr)
explicitnoexcept
Parameters
ptrNote that this ptr could have a non-zero reference count, and this ctor will take ownership of the ptr, respecting that reference count, only deleting the ptr if it reaches zero. The type of the parameter must be the same type or a class non-privately derived from value_type.

◆ unique_ptr() [8/13]

template<class V , class LkT >
template<class V2 , class LkT2 >
__stdcall FORCE_INLINE jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::unique_ptr ( unique_ptr< V2, LkT2 > &&  s)
explicitnoexcept

Note that the same deleter and threading model must be specified.

Parameters
sThe type of the parameter must be the same type or a class non-privately derived from value_type.

◆ unique_ptr() [9/13]

template<class V , class LkT >
constexpr jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::unique_ptr ( unique_ptr< V, LkT > &&  s)
inlineconstexprnoexcept

Definition at line 105 of file unique_ptr_impl.hpp.

◆ ~unique_ptr()

template<class V , class LkT >
jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::~unique_ptr
inlinenoexcept
See also
reset()

Definition at line 117 of file unique_ptr_impl.hpp.

◆ unique_ptr() [10/13]

template<class V , class LkT >
template<class V1 >
jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::unique_ptr ( V1 *  ptr)
inlinenoexcept

Definition at line 63 of file unique_ptr_impl.hpp.

◆ unique_ptr() [11/13]

template<class V , class LkT >
template<class V1 , template< class > class At>
jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::unique_ptr ( At< V1 * > &&  ptr)
inlinenoexcept

Definition at line 78 of file unique_ptr_impl.hpp.

◆ unique_ptr() [12/13]

template<class V , class LkT >
template<class V1 >
jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::unique_ptr ( std::unique_ptr< V1, typename V1::deleter_t > &&  d)
inlinenoexcept

Definition at line 96 of file unique_ptr_impl.hpp.

◆ unique_ptr() [13/13]

template<class V , class LkT >
template<typename V2 , class LkT2 >
jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::unique_ptr ( unique_ptr< V2, LkT2 > &&  s)
inlinenoexcept

Definition at line 111 of file unique_ptr_impl.hpp.

Member Function Documentation

◆ get() [1/2]

template<class V , class LkT >
constexpr unique_ptr< V, LkT >::atomic_ptr_t const & jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::get
inlineconstexprnoexcept

Definition at line 161 of file unique_ptr_impl.hpp.

◆ get() [2/2]

template<class V , class LkT >
unique_ptr< V, LkT >::atomic_ptr_t & jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::get
inlinenoexcept

Definition at line 165 of file unique_ptr_impl.hpp.

◆ operator bool()

template<class V , class LkT >
constexpr jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::operator bool
inlineexplicitconstexprnoexcept

Definition at line 152 of file unique_ptr_impl.hpp.

◆ operator!=()

template<class V , class LkT >
constexpr bool jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::operator!= ( const unique_ptr< V, LkT > &  s) const
inlineconstexprnoexcept

Definition at line 148 of file unique_ptr_impl.hpp.

◆ operator*() [1/2]

template<class V , class LkT >
constexpr unique_ptr< V, LkT >::value_type const & jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::operator*
inlineconstexprnoexcept

Definition at line 169 of file unique_ptr_impl.hpp.

◆ operator*() [2/2]

template<class V , class LkT >
unique_ptr< V, LkT >::value_type & jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::operator*
inlinenoexcept

Definition at line 174 of file unique_ptr_impl.hpp.

◆ operator->() [1/2]

template<class V , class LkT >
constexpr unique_ptr< V, LkT >::value_type const * jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::operator->
inlineconstexprnoexcept

Definition at line 179 of file unique_ptr_impl.hpp.

◆ operator->() [2/2]

template<class V , class LkT >
unique_ptr< V, LkT >::value_type * jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::operator->
inlinenoexcept

Definition at line 183 of file unique_ptr_impl.hpp.

◆ operator<()

template<class V , class LkT >
constexpr bool jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::operator< ( const unique_ptr< V, LkT > &  s) const
inlineconstexprnoexcept

Definition at line 139 of file unique_ptr_impl.hpp.

◆ operator=() [1/2]

template<class V , class LkT >
void jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::operator= ( unique_ptr< V, LkT > &&  s)
inlinenoexcept

◆ operator=() [2/2]

template<class V , class LkT >
template<typename V2 , class LkT2 >
void jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::operator= ( unique_ptr< V2, LkT2 > &&  s)
inlinenoexcept

Note that the same deleter and threading model must be specified.

Parameters
sThe type of the parameter must be the same type or a class non-privately derived from value_type.

Definition at line 127 of file unique_ptr_impl.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::reset().

◆ operator==()

template<class V , class LkT >
constexpr bool jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::operator== ( const unique_ptr< V, LkT > &  s) const
inlineconstexprnoexcept

Definition at line 144 of file unique_ptr_impl.hpp.

◆ operator>()

template<class V , class LkT >
constexpr bool jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::operator> ( const unique_ptr< V, LkT > &  s) const
inlineconstexprnoexcept

Definition at line 156 of file unique_ptr_impl.hpp.

◆ release()

template<class V , class LkT >
unique_ptr< V, LkT >::atomic_ptr_t jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::release
inlinenoexcept

Release the contained object from control.

Definition at line 24 of file unique_ptr_impl.hpp.

◆ reset()

template<class V , class LkT >
void jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::reset ( void  )
inlinenoexcept

◆ swap() [1/5]

template<class V , class LkT >
void jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::swap ( unique_ptr< V, LkT > &  s)
inlinenoexcept

Definition at line 37 of file unique_ptr_impl.hpp.

◆ swap() [2/5]

template<class V , class LkT >
template<class V1 >
__fastcall void FORCE_INLINE jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::swap ( unique_ptr< V1, LkT > &  s)
noexcept

◆ swap() [3/5]

template<class V , class LkT >
template<class V1 >
void jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::swap ( unique_ptr< V1, LkT > &  s)
inlinenoexcept

Definition at line 43 of file unique_ptr_impl.hpp.

◆ swap() [4/5]

template<class V , class LkT >
template<class V2 , class LkT2 >
__fastcall void FORCE_INLINE jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::swap ( unique_ptr< V2, LkT2 > &  s)
noexcept

◆ swap() [5/5]

template<class V , class LkT >
template<class V2 , class LkT2 >
void jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::swap ( unique_ptr< V2, LkT2 > &  s)
inlinenoexcept

Definition at line 50 of file unique_ptr_impl.hpp.

◆ to_string()

template<class V , class LkT >
tstring jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::to_string
inlinenoexcept

Definition at line 188 of file unique_ptr_impl.hpp.

Friends And Related Function Documentation

◆ operator<<

template<class V , class LkT >
tostream& __fastcall operator<< ( tostream os,
unique_ptr< V, LkT > const &  ptr 
)
friend
Todo:
Implement using the advice given in "Standard C++ IOStreams and Locales" by A.Langer & K.Kreft, page 170.

Definition at line 164 of file unique_ptr.hpp.

◆ unique_ptr

template<class V , class LkT >
template<class , class >
friend class unique_ptr
friend

Member Data Documentation

◆ memory_access_mode

template<class V , class LkT >
constexpr ppd::generic_traits::memory_access_modes jmmcg::LIBJMMCG_VER_NAMESPACE::unique_ptr< V, LkT >::memory_access_mode =atomic_ptr_t::memory_access_mode
staticconstexpr

To assist in allowing compile-time computation of the algorithmic order of the threading model.

Definition at line 59 of file unique_ptr.hpp.


The documentation for this class was generated from the following files: