cycle_ptr
Public Types | Public Member Functions | Friends | Related Functions | List of all members
cycle_ptr::cycle_member_ptr< T > Class Template Reference

Pointer between objects participating in the cycle_ptr graph. More...

#include <cycle_ptr.h>

Inheritance diagram for cycle_ptr::cycle_member_ptr< T >:
Inheritance graph
[legend]
Collaboration diagram for cycle_ptr::cycle_member_ptr< T >:
Collaboration graph
[legend]

Public Types

using element_type = std::remove_extent_t< T >
 Element type of this pointer.
 
using weak_type = cycle_weak_ptr< T >
 Weak pointer equivalent.
 

Public Member Functions

 cycle_member_ptr ([[maybe_unused]] unowned_cycle_t unowned_tag) noexcept
 Create an unowned member pointer, representing a nullptr. More...
 
 cycle_member_ptr (unowned_cycle_t unowned_tag, [[maybe_unused]] std::nullptr_t nil) noexcept
 Create an unowned member pointer, representing a nullptr. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
 cycle_member_ptr ([[maybe_unused]] unowned_cycle_t unowned_tag, const cycle_member_ptr< U > &ptr)
 Create an unowned member pointer, pointing at ptr. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
 cycle_member_ptr (unowned_cycle_t unowned_tag, cycle_member_ptr< U > &&ptr)
 Create an unowned member pointer, pointing at ptr. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
 cycle_member_ptr ([[maybe_unused]] unowned_cycle_t unowned_tag, const cycle_gptr< U > &ptr)
 Create an unowned member pointer, pointing at ptr. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
 cycle_member_ptr ([[maybe_unused]] unowned_cycle_t unowned_tag, cycle_gptr< U > &&ptr)
 Create an unowned member pointer, pointing at ptr. More...
 
template<typename U >
 cycle_member_ptr ([[maybe_unused]] unowned_cycle_t unowned_tag, const cycle_member_ptr< U > &ptr, element_type *target)
 Aliasing constructor for unowned member pointer. More...
 
template<typename U >
 cycle_member_ptr ([[maybe_unused]] unowned_cycle_t unowned_tag, const cycle_gptr< U > &ptr, element_type *target)
 Aliasing constructor for unowned member pointer. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
 cycle_member_ptr (unowned_cycle_t unowned_tag, const cycle_weak_ptr< U > &ptr)
 Create an unowned member pointer, pointing at ptr. More...
 
 cycle_member_ptr (cycle_base &owner) noexcept
 Constructor with explicitly specified ownership. More...
 
 cycle_member_ptr (cycle_base &owner, [[maybe_unused]] std::nullptr_t nil) noexcept
 Constructor with explicitly specified ownership. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
 cycle_member_ptr (cycle_base &owner, const cycle_member_ptr< U > &ptr)
 Constructor with explicitly specified ownership. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
 cycle_member_ptr (cycle_base &owner, cycle_member_ptr< U > &&ptr)
 Constructor with explicitly specified ownership. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
 cycle_member_ptr (cycle_base &owner, const cycle_gptr< U > &ptr)
 Constructor with explicitly specified ownership. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
 cycle_member_ptr (cycle_base &owner, cycle_gptr< U > &&ptr)
 Constructor with explicitly specified ownership. More...
 
template<typename U >
 cycle_member_ptr (cycle_base &owner, const cycle_member_ptr< U > &ptr, element_type *target)
 Aliasing constructor with explicitly specified ownership. More...
 
template<typename U >
 cycle_member_ptr (cycle_base &owner, const cycle_gptr< U > &ptr, element_type *target)
 Aliasing constructor with explicitly specified ownership. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
 cycle_member_ptr (cycle_base &owner, const cycle_weak_ptr< U > &ptr)
 Constructor with explicitly specified ownership. More...
 
 cycle_member_ptr ()
 Constructor with automatic ownership detection. More...
 
 cycle_member_ptr ([[maybe_unused]] std::nullptr_t nil)
 Constructor with automatic ownership detection. More...
 
 cycle_member_ptr (const cycle_member_ptr &ptr)
 Constructor with automatic ownership detection. More...
 
 cycle_member_ptr (cycle_member_ptr &&ptr)
 Constructor with automatic ownership detection. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
 cycle_member_ptr (const cycle_member_ptr< U > &ptr)
 Constructor with automatic ownership detection. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
 cycle_member_ptr (cycle_member_ptr< U > &&ptr)
 Constructor with automatic ownership detection. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
 cycle_member_ptr (const cycle_gptr< U > &ptr)
 Constructor with automatic ownership detection. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
 cycle_member_ptr (cycle_gptr< U > &&ptr)
 Constructor with automatic ownership detection. More...
 
template<typename U >
 cycle_member_ptr (const cycle_member_ptr< U > &ptr, element_type *target)
 Aliasing constructor with automatic ownership detection. More...
 
template<typename U >
 cycle_member_ptr (const cycle_gptr< U > &ptr, element_type *target)
 Aliasing constructor with automatic ownership detection. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
 cycle_member_ptr (const cycle_weak_ptr< U > &ptr)
 Constructor with automatic ownership detection. More...
 
auto operator= ([[maybe_unused]] std::nullptr_t nil) -> cycle_member_ptr &
 Assignment operator. More...
 
auto operator= (const cycle_member_ptr &other) -> cycle_member_ptr &
 Copy assignment operator. More...
 
auto operator= (cycle_member_ptr &&other) -> cycle_member_ptr &
 Move assignment operator. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
auto operator= (const cycle_member_ptr< U > &other) -> cycle_member_ptr &
 Copy assignment operator. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
auto operator= (cycle_member_ptr< U > &&other) -> cycle_member_ptr &
 Move assignment operator. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
auto operator= (const cycle_gptr< U > &other) -> cycle_member_ptr &
 Copy assignment operator. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
auto operator= (cycle_gptr< U > &&other) -> cycle_member_ptr &
 Move assignment operator. More...
 
auto reset () -> void
 Clear this pointer. More...
 
auto swap (cycle_member_ptr &other) -> void
 Swap with other pointer. More...
 
auto swap (cycle_gptr< T > &other) -> void
 Swap with other pointer. More...
 
auto get () const -> T *
 Returns the raw pointer of this. More...
 
template<bool Enable = !std::is_void_v<T>>
auto operator * () const -> std::enable_if_t< Enable, T > &
 Dereference operation. More...
 
template<bool Enable = !std::is_void_v<T>>
auto operator-> () const -> std::enable_if_t< Enable, T > *
 Indirection operation. More...
 
 operator bool () const
 Test if this pointer points holds a non-nullptr value. More...
 
template<typename U >
auto owner_before (const cycle_weak_ptr< U > &other) const noexcept -> bool
 Ownership ordering.
 
template<typename U >
auto owner_before (const cycle_gptr< U > &other) const noexcept -> bool
 Ownership ordering.
 
template<typename U >
auto owner_before (const cycle_member_ptr< U > &other) const noexcept -> bool
 Ownership ordering.
 

Friends

template<typename >
class cycle_member_ptr
 
template<typename >
class cycle_gptr
 
template<typename >
class cycle_weak_ptr
 

Related Functions

(Note that these are not member functions.)

template<typename T , typename U >
auto operator== (const cycle_member_ptr< T > &x, const cycle_member_ptr< U > &y) noexcept -> bool
 Equality comparison. More...
 
template<typename T >
auto operator== (const cycle_member_ptr< T > &x, [[maybe_unused]] std::nullptr_t y) noexcept -> bool
 Equality comparison. More...
 
template<typename U >
auto operator== ([[maybe_unused]] std::nullptr_t x, const cycle_member_ptr< U > &y) noexcept -> bool
 Equality comparison. More...
 
template<typename T , typename U >
auto operator!= (const cycle_member_ptr< T > &x, const cycle_member_ptr< U > &y) noexcept -> bool
 Inequality comparison. More...
 
template<typename T >
auto operator!= (const cycle_member_ptr< T > &x, [[maybe_unused]] std::nullptr_t y) noexcept -> bool
 Inequality comparison. More...
 
template<typename U >
auto operator!= ([[maybe_unused]] std::nullptr_t x, const cycle_member_ptr< U > &y) noexcept -> bool
 Inequality comparison. More...
 
template<typename T , typename U >
auto operator< (const cycle_member_ptr< T > &x, const cycle_member_ptr< U > &y) noexcept -> bool
 Less comparison. More...
 
template<typename T >
auto operator< (const cycle_member_ptr< T > &x, [[maybe_unused]] std::nullptr_t y) noexcept -> bool
 Less comparison. More...
 
template<typename U >
auto operator< ([[maybe_unused]] std::nullptr_t x, const cycle_member_ptr< U > &y) noexcept -> bool
 Less comparison. More...
 
template<typename T , typename U >
auto operator> (const cycle_member_ptr< T > &x, const cycle_member_ptr< U > &y) noexcept -> bool
 Greater comparison. More...
 
template<typename T >
auto operator> (const cycle_member_ptr< T > &x, [[maybe_unused]] std::nullptr_t y) noexcept -> bool
 Greater comparison. More...
 
template<typename U >
auto operator> ([[maybe_unused]] std::nullptr_t x, const cycle_member_ptr< U > &y) noexcept -> bool
 Greater comparison. More...
 
template<typename T , typename U >
auto operator<= (const cycle_member_ptr< T > &x, const cycle_member_ptr< U > &y) noexcept -> bool
 Less or equal comparison. More...
 
template<typename T >
auto operator<= (const cycle_member_ptr< T > &x, [[maybe_unused]] std::nullptr_t y) noexcept -> bool
 Less or equal comparison. More...
 
template<typename U >
auto operator<= ([[maybe_unused]] std::nullptr_t x, const cycle_member_ptr< U > &y) noexcept -> bool
 Less or equal comparison. More...
 
template<typename T , typename U >
auto operator>= (const cycle_member_ptr< T > &x, const cycle_member_ptr< U > &y) noexcept -> bool
 Greater or equal comparison. More...
 
template<typename T >
auto operator>= (const cycle_member_ptr< T > &x, [[maybe_unused]] std::nullptr_t y) noexcept -> bool
 Greater or equal comparison. More...
 
template<typename U >
auto operator>= ([[maybe_unused]] std::nullptr_t x, const cycle_member_ptr< U > &y) noexcept -> bool
 Greater or equal comparison. More...
 
template<typename T >
auto swap (cycle_member_ptr< T > &x, cycle_member_ptr< T > &y) noexcept -> void
 Swap two pointers. More...
 
template<typename T >
auto swap (cycle_gptr< T > &x, cycle_member_ptr< T > &y) noexcept -> void
 Swap two pointers.
 
template<typename T , typename U >
auto operator== (const cycle_gptr< T > &x, const cycle_member_ptr< U > &y) noexcept -> bool
 Equality comparison.
 
template<typename T , typename U >
auto operator== (const cycle_member_ptr< T > &x, const cycle_gptr< U > &y) noexcept -> bool
 Equality comparison.
 
template<typename T , typename U >
auto operator!= (const cycle_gptr< T > &x, const cycle_member_ptr< U > &y) noexcept -> bool
 Inequality comparison.
 
template<typename T , typename U >
auto operator!= (const cycle_member_ptr< T > &x, const cycle_gptr< U > &y) noexcept -> bool
 Inequality comparison.
 
template<typename T , typename U >
auto operator< (const cycle_gptr< T > &x, const cycle_member_ptr< U > &y) noexcept -> bool
 Less comparison.
 
template<typename T , typename U >
auto operator< (const cycle_member_ptr< T > &x, const cycle_gptr< U > &y) noexcept -> bool
 Less comparison.
 
template<typename T , typename U >
auto operator> (const cycle_gptr< T > &x, const cycle_member_ptr< U > &y) noexcept -> bool
 Greater comparison.
 
template<typename T , typename U >
auto operator> (const cycle_member_ptr< T > &x, const cycle_gptr< U > &y) noexcept -> bool
 Greater comparison.
 
template<typename T , typename U >
auto operator<= (const cycle_gptr< T > &x, const cycle_member_ptr< U > &y) noexcept -> bool
 Less or equal comparison.
 
template<typename T , typename U >
auto operator<= (const cycle_member_ptr< T > &x, const cycle_gptr< U > &y) noexcept -> bool
 Less or equal comparison.
 
template<typename T , typename U >
auto operator>= (const cycle_gptr< T > &x, const cycle_member_ptr< U > &y) noexcept -> bool
 Greater or equal comparison.
 
template<typename T , typename U >
auto operator>= (const cycle_member_ptr< T > &x, const cycle_gptr< U > &y) noexcept -> bool
 Greater or equal comparison.
 
template<typename Char , typename Traits , typename T >
auto operator<< (std::basic_ostream< Char, Traits > &out, const cycle_member_ptr< T > &ptr) -> std::basic_ostream< Char, Traits > &
 Write pointer to output stream. More...
 
template<typename T , typename U = cycle_ptr::cycle_gptr<T>>
auto exchange (cycle_ptr::cycle_member_ptr< T > &x, U &&y)
 Specialize std::exchange. More...
 
template<typename T , typename U >
auto static_pointer_cast (const cycle_ptr::cycle_member_ptr< U > &r) -> cycle_ptr::cycle_gptr< T >
 Perform static cast on pointer. More...
 
template<typename T , typename U >
auto dynamic_pointer_cast (const cycle_ptr::cycle_member_ptr< U > &r) -> cycle_ptr::cycle_gptr< T >
 Perform dynamic cast on pointer. More...
 
template<typename T , typename U >
auto const_pointer_cast (const cycle_ptr::cycle_member_ptr< U > &r) -> cycle_ptr::cycle_gptr< T >
 Perform const cast on pointer. More...
 
template<typename T , typename U >
auto reinterpret_pointer_cast (const cycle_ptr::cycle_member_ptr< U > &r) -> cycle_ptr::cycle_gptr< T >
 Perform reinterpret cast on pointer. More...
 

Detailed Description

template<typename T>
class cycle_ptr::cycle_member_ptr< T >

Pointer between objects participating in the cycle_ptr graph.

This smart pointer models the relationship between an origin object and a target object.

It is intended for use in member variables, as well as collections that are owned by a member variable.

Constructor & Destructor Documentation

◆ cycle_member_ptr() [1/29]

template<typename T>
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( [[maybe_unused] ] unowned_cycle_t  unowned_tag)
inlineexplicitnoexcept

Create an unowned member pointer, representing a nullptr.

Makes this cycle_member_ptr behave like a cycle_gptr.

Useful for instance when you need a cycle_member_ptr to pass as argument to a std::map::find() function, for instance:

std::map<
cycle_member_ptr<Key>, Value,
std::less<cycle_member_ptr<Key>>,
cycle_allocator<std::allocator<std::pair<const cycle_member_ptr<Key>, Value>>>>
someMap;
cycle_gptr<Key> soughtKey;
// This will fail, as conversion from cycle_gptr to cycle_member_ptr
// without declared ownership uses automatic ownership, but none is
// published.
// It will fail with std::runtime_error.
someMap.find(soughtKey);
// This will succeed, as conversion now explicitly declares
// the argument to std::map::find() to have the correct type.
someMap.find(cycle_member_ptr<Key>(unowned_cycle, soughtKey));
// Braces initalization should also work:
someMap.find({unowned_cycle, soughtKey});
Postcondition
*this == nullptr
Parameters
unowned_tagTag to select ownerless construction.

◆ cycle_member_ptr() [2/29]

template<typename T>
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( unowned_cycle_t  unowned_tag,
[[maybe_unused] ] std::nullptr_t  nil 
)
inlinenoexcept

Create an unowned member pointer, representing a nullptr.

Makes this cycle_member_ptr behave like a cycle_gptr.

Useful for instance when you need a cycle_member_ptr to pass as argument to a std::map::find() function, for instance:

std::map<
cycle_member_ptr<Key>, Value,
std::less<cycle_member_ptr<Key>>,
cycle_allocator<std::allocator<std::pair<const cycle_member_ptr<Key>, Value>>>>
someMap;
cycle_gptr<Key> soughtKey;
// This will fail, as conversion from cycle_gptr to cycle_member_ptr
// without declared ownership uses automatic ownership, but none is
// published.
// It will fail with std::runtime_error.
someMap.find(soughtKey);
// This will succeed, as conversion now explicitly declares
// the argument to std::map::find() to have the correct type.
someMap.find(cycle_member_ptr<Key>(unowned_cycle, soughtKey));
// Braces initalization should also work:
someMap.find({unowned_cycle, soughtKey});
Postcondition
*this == nullptr
Parameters
unowned_tagTag to select ownerless construction.
nilNullptr value.

◆ cycle_member_ptr() [3/29]

template<typename T>
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( [[maybe_unused] ] unowned_cycle_t  unowned_tag,
const cycle_member_ptr< U > &  ptr 
)
inline

Create an unowned member pointer, pointing at ptr.

Makes this cycle_member_ptr behave like a cycle_gptr.

Useful for instance when you need a cycle_member_ptr to pass as argument to a std::map::find() function, for instance:

std::map<
cycle_member_ptr<Key>, Value,
std::less<cycle_member_ptr<Key>>,
cycle_allocator<std::allocator<std::pair<const cycle_member_ptr<Key>, Value>>>>
someMap;
cycle_gptr<Key> soughtKey;
// This will fail, as conversion from cycle_gptr to cycle_member_ptr
// without declared ownership uses automatic ownership, but none is
// published.
// It will fail with std::runtime_error.
someMap.find(soughtKey);
// This will succeed, as conversion now explicitly declares
// the argument to std::map::find() to have the correct type.
someMap.find(cycle_member_ptr<Key>(unowned_cycle, soughtKey));
// Braces initalization should also work:
someMap.find({unowned_cycle, soughtKey});
Postcondition
*this == ptr
Parameters
unowned_tagTag to select ownerless construction.
ptrInitialize to point at this same object.

◆ cycle_member_ptr() [4/29]

template<typename T>
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( unowned_cycle_t  unowned_tag,
cycle_member_ptr< U > &&  ptr 
)
inline

Create an unowned member pointer, pointing at ptr.

Makes this cycle_member_ptr behave like a cycle_gptr.

Useful for instance when you need a cycle_member_ptr to pass as argument to a std::map::find() function, for instance:

std::map<
cycle_member_ptr<Key>, Value,
std::less<cycle_member_ptr<Key>>,
cycle_allocator<std::allocator<std::pair<const cycle_member_ptr<Key>, Value>>>>
someMap;
cycle_gptr<Key> soughtKey;
// This will fail, as conversion from cycle_gptr to cycle_member_ptr
// without declared ownership uses automatic ownership, but none is
// published.
// It will fail with std::runtime_error.
someMap.find(soughtKey);
// This will succeed, as conversion now explicitly declares
// the argument to std::map::find() to have the correct type.
someMap.find(cycle_member_ptr<Key>(unowned_cycle, soughtKey));
// Braces initalization should also work:
someMap.find({unowned_cycle, soughtKey});
Postcondition
*this == original value of ptr
ptr == nullptr
Parameters
unowned_tagTag to select ownerless construction.
ptrInitialize to point at this same object.

◆ cycle_member_ptr() [5/29]

template<typename T>
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( [[maybe_unused] ] unowned_cycle_t  unowned_tag,
const cycle_gptr< U > &  ptr 
)
inline

Create an unowned member pointer, pointing at ptr.

Makes this cycle_member_ptr behave like a cycle_gptr.

Useful for instance when you need a cycle_member_ptr to pass as argument to a std::map::find() function, for instance:

std::map<
cycle_member_ptr<Key>, Value,
std::less<cycle_member_ptr<Key>>,
cycle_allocator<std::allocator<std::pair<const cycle_member_ptr<Key>, Value>>>>
someMap;
cycle_gptr<Key> soughtKey;
// This will fail, as conversion from cycle_gptr to cycle_member_ptr
// without declared ownership uses automatic ownership, but none is
// published.
// It will fail with std::runtime_error.
someMap.find(soughtKey);
// This will succeed, as conversion now explicitly declares
// the argument to std::map::find() to have the correct type.
someMap.find(cycle_member_ptr<Key>(unowned_cycle, soughtKey));
// Braces initalization should also work:
someMap.find({unowned_cycle, soughtKey});
Postcondition
*this == ptr
Parameters
unowned_tagTag to select ownerless construction.
ptrInitialize to point at this same object.

◆ cycle_member_ptr() [6/29]

template<typename T>
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( [[maybe_unused] ] unowned_cycle_t  unowned_tag,
cycle_gptr< U > &&  ptr 
)
inline

Create an unowned member pointer, pointing at ptr.

Makes this cycle_member_ptr behave like a cycle_gptr.

Useful for instance when you need a cycle_member_ptr to pass as argument to a std::map::find() function, for instance:

std::map<
cycle_member_ptr<Key>, Value,
std::less<cycle_member_ptr<Key>>,
cycle_allocator<std::allocator<std::pair<const cycle_member_ptr<Key>, Value>>>>
someMap;
cycle_gptr<Key> soughtKey;
// This will fail, as conversion from cycle_gptr to cycle_member_ptr
// without declared ownership uses automatic ownership, but none is
// published.
// It will fail with std::runtime_error.
someMap.find(soughtKey);
// This will succeed, as conversion now explicitly declares
// the argument to std::map::find() to have the correct type.
someMap.find(cycle_member_ptr<Key>(unowned_cycle, soughtKey));
// Braces initalization should also work:
someMap.find({unowned_cycle, soughtKey});
Postcondition
*this == original value of ptr
ptr == nullptr
Parameters
unowned_tagTag to select ownerless construction.
ptrInitialize to point at this same object.

◆ cycle_member_ptr() [7/29]

template<typename T>
template<typename U >
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( [[maybe_unused] ] unowned_cycle_t  unowned_tag,
const cycle_member_ptr< U > &  ptr,
element_type target 
)
inline

Aliasing constructor for unowned member pointer.

Makes this cycle_member_ptr behave like a cycle_gptr.

Postcondition
control block of *this == control block of ptr
this->get() == target
Exceptions
std::bad_weak_ptrIf ptr is owned by an expired owner.
Bug:
It looks like std::shared_ptr allows similar aliases to be constructed without ptr having ownership of anything, yet still pointing at target. This case is currently unspecified in cycle_ptr library.

◆ cycle_member_ptr() [8/29]

template<typename T>
template<typename U >
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( [[maybe_unused] ] unowned_cycle_t  unowned_tag,
const cycle_gptr< U > &  ptr,
element_type target 
)
inline

Aliasing constructor for unowned member pointer.

Makes this cycle_member_ptr behave like a cycle_gptr.

Postcondition
control block of *this == control block of ptr
this->get() == target
Bug:
It looks like std::shared_ptr allows similar aliases to be constructed without ptr having ownership of anything, yet still pointing at target. This case is currently unspecified in cycle_ptr library.

◆ cycle_member_ptr() [9/29]

template<typename T>
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( unowned_cycle_t  unowned_tag,
const cycle_weak_ptr< U > &  ptr 
)
inline

Create an unowned member pointer, pointing at ptr.

Makes this cycle_member_ptr behave like a cycle_gptr.

Useful for instance when you need a cycle_member_ptr to pass as argument to a std::map::find() function, for instance:

std::map<
cycle_member_ptr<Key>, Value,
std::less<cycle_member_ptr<Key>>,
cycle_allocator<std::allocator<std::pair<const cycle_member_ptr<Key>, Value>>>>
someMap;
cycle_gptr<Key> soughtKey;
// This will fail, as conversion from cycle_gptr to cycle_member_ptr
// without declared ownership uses automatic ownership, but none is
// published.
// It will fail with std::runtime_error.
someMap.find(soughtKey);
// This will succeed, as conversion now explicitly declares
// the argument to std::map::find() to have the correct type.
someMap.find(cycle_member_ptr<Key>(unowned_cycle, soughtKey));
// Braces initalization should also work:
someMap.find({unowned_cycle, soughtKey});
Postcondition
*this == ptr.lock()
Parameters
unowned_tagTag to select ownerless construction.
ptrInitialize to point at this same object.
Exceptions
std::bad_weak_ptrIf the weak pointer is expired.

◆ cycle_member_ptr() [10/29]

template<typename T>
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( cycle_base owner)
inlineexplicitnoexcept

Constructor with explicitly specified ownership.

Creates a pointer owned by this owner.

Postcondition
*this == nullptr
Parameters
ownerThe owner object of this member pointer.

◆ cycle_member_ptr() [11/29]

template<typename T>
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( cycle_base owner,
[[maybe_unused] ] std::nullptr_t  nil 
)
inlinenoexcept

Constructor with explicitly specified ownership.

Creates a pointer owned by this owner.

Postcondition
*this == nullptr
Parameters
ownerThe owner object of this member pointer.
nilnullptr

◆ cycle_member_ptr() [12/29]

template<typename T>
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( cycle_base owner,
const cycle_member_ptr< U > &  ptr 
)
inline

Constructor with explicitly specified ownership.

Creates a pointer owned by this owner.

Postcondition
*this == ptr
Parameters
ownerThe owner object of this member pointer.
ptrPointer to initalize with.

◆ cycle_member_ptr() [13/29]

template<typename T>
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( cycle_base owner,
cycle_member_ptr< U > &&  ptr 
)
inline

Constructor with explicitly specified ownership.

Creates a pointer owned by this owner.

Postcondition
*this == original value of ptr
ptr == nullptr
Parameters
ownerThe owner object of this member pointer.
ptrPointer to initalize with.

◆ cycle_member_ptr() [14/29]

template<typename T>
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( cycle_base owner,
const cycle_gptr< U > &  ptr 
)
inline

Constructor with explicitly specified ownership.

Creates a pointer owned by this owner.

Postcondition
*this == ptr
Parameters
ownerThe owner object of this member pointer.
ptrPointer to initalize with.

◆ cycle_member_ptr() [15/29]

template<typename T>
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( cycle_base owner,
cycle_gptr< U > &&  ptr 
)
inline

Constructor with explicitly specified ownership.

Creates a pointer owned by this owner.

Postcondition
*this == original value of ptr
ptr == nullptr
Parameters
ownerThe owner object of this member pointer.
ptrPointer to initalize with.

◆ cycle_member_ptr() [16/29]

template<typename T>
template<typename U >
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( cycle_base owner,
const cycle_member_ptr< U > &  ptr,
element_type target 
)
inline

Aliasing constructor with explicitly specified ownership.

Creates a pointer owned by this owner.

Postcondition
control block of *this == control block of ptr
this->get() == target
Parameters
ownerThe owner object of this member pointer.
ptrPointer to initalize with.
targetThe alias pointer.
Bug:
It looks like std::shared_ptr allows similar aliases to be constructed without ptr having ownership of anything, yet still pointing at target. This case is currently unspecified in cycle_ptr library.

◆ cycle_member_ptr() [17/29]

template<typename T>
template<typename U >
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( cycle_base owner,
const cycle_gptr< U > &  ptr,
element_type target 
)
inline

Aliasing constructor with explicitly specified ownership.

Creates a pointer owned by this owner.

Postcondition
control block of *this == control block of ptr
this->get() == target
Parameters
ownerThe owner object of this member pointer.
ptrPointer to initalize with.
targetThe alias pointer.
Bug:
It looks like std::shared_ptr allows similar aliases to be constructed without ptr having ownership of anything, yet still pointing at target. This case is currently unspecified in cycle_ptr library.

◆ cycle_member_ptr() [18/29]

template<typename T>
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( cycle_base owner,
const cycle_weak_ptr< U > &  ptr 
)
inline

Constructor with explicitly specified ownership.

Postcondition
*this == ptr.lock()
Parameters
ownerThe owner object of this member pointer.
ptrInitialize to point at this same object.
Exceptions
std::bad_weak_ptrIf the weak pointer is expired.

◆ cycle_member_ptr() [19/29]

template<typename T>
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( )
inline

Constructor with automatic ownership detection.

Uses publisher logic to figure out the ownership.

cycle_ptr::allocate_cycle, cycle_ptr::make_cycle, and cycle_ptr::cycle_allocator publish their control block, which is automatically picked up by this contructor.

Postcondition
*this == nullptr
Exceptions
std::runtime_errorIf no published control block covers the address range of *this.

◆ cycle_member_ptr() [20/29]

template<typename T>
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( [[maybe_unused] ] std::nullptr_t  nil)
inline

Constructor with automatic ownership detection.

Uses publisher logic to figure out the ownership.

cycle_ptr::allocate_cycle, cycle_ptr::make_cycle, and cycle_ptr::cycle_allocator publish their control block, which is automatically picked up by this contructor.

Postcondition
*this == nullptr
Exceptions
std::runtime_errorIf no published control block covers the address range of *this.

◆ cycle_member_ptr() [21/29]

template<typename T>
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( const cycle_member_ptr< T > &  ptr)
inline

Constructor with automatic ownership detection.

Uses publisher logic to figure out the ownership.

cycle_ptr::allocate_cycle, cycle_ptr::make_cycle, and cycle_ptr::cycle_allocator publish their control block, which is automatically picked up by this contructor.

Postcondition
*this == ptr
Exceptions
std::runtime_errorIf no published control block covers the address range of *this.

◆ cycle_member_ptr() [22/29]

template<typename T>
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( cycle_member_ptr< T > &&  ptr)
inline

Constructor with automatic ownership detection.

Uses publisher logic to figure out the ownership.

cycle_ptr::allocate_cycle, cycle_ptr::make_cycle, and cycle_ptr::cycle_allocator publish their control block, which is automatically picked up by this contructor.

Postcondition
*this == original value of ptr
ptr == nullptr
Exceptions
std::runtime_errorIf no published control block covers the address range of *this.

◆ cycle_member_ptr() [23/29]

template<typename T>
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( const cycle_member_ptr< U > &  ptr)
inline

Constructor with automatic ownership detection.

Uses publisher logic to figure out the ownership.

cycle_ptr::allocate_cycle, cycle_ptr::make_cycle, and cycle_ptr::cycle_allocator publish their control block, which is automatically picked up by this contructor.

Postcondition
*this == ptr
Exceptions
std::runtime_errorIf no published control block covers the address range of *this.

◆ cycle_member_ptr() [24/29]

template<typename T>
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( cycle_member_ptr< U > &&  ptr)
inline

Constructor with automatic ownership detection.

Uses publisher logic to figure out the ownership.

cycle_ptr::allocate_cycle, cycle_ptr::make_cycle, and cycle_ptr::cycle_allocator publish their control block, which is automatically picked up by this contructor.

Postcondition
*this == original value of ptr
ptr == nullptr
Exceptions
std::runtime_errorIf no published control block covers the address range of *this.

◆ cycle_member_ptr() [25/29]

template<typename T>
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( const cycle_gptr< U > &  ptr)
inline

Constructor with automatic ownership detection.

Uses publisher logic to figure out the ownership.

cycle_ptr::allocate_cycle, cycle_ptr::make_cycle, and cycle_ptr::cycle_allocator publish their control block, which is automatically picked up by this contructor.

Postcondition
*this == ptr
Exceptions
std::runtime_errorIf no published control block covers the address range of *this.

◆ cycle_member_ptr() [26/29]

template<typename T>
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( cycle_gptr< U > &&  ptr)
inline

Constructor with automatic ownership detection.

Uses publisher logic to figure out the ownership.

cycle_ptr::allocate_cycle, cycle_ptr::make_cycle, and cycle_ptr::cycle_allocator publish their control block, which is automatically picked up by this contructor.

Postcondition
*this == original value of ptr
ptr == nullptr
Exceptions
std::runtime_errorIf no published control block covers the address range of *this.

◆ cycle_member_ptr() [27/29]

template<typename T>
template<typename U >
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( const cycle_member_ptr< U > &  ptr,
element_type target 
)
inline

Aliasing constructor with automatic ownership detection.

Uses publisher logic to figure out the ownership.

cycle_ptr::allocate_cycle, cycle_ptr::make_cycle, and cycle_ptr::cycle_allocator publish their control block, which is automatically picked up by this contructor.

Postcondition
control block of *this == control block of ptr
this->get() == target
Exceptions
std::runtime_errorIf no published control block covers the address range of *this.

◆ cycle_member_ptr() [28/29]

template<typename T>
template<typename U >
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( const cycle_gptr< U > &  ptr,
element_type target 
)
inline

Aliasing constructor with automatic ownership detection.

Uses publisher logic to figure out the ownership.

cycle_ptr::allocate_cycle, cycle_ptr::make_cycle, and cycle_ptr::cycle_allocator publish their control block, which is automatically picked up by this contructor.

Postcondition
control block of *this == control block of ptr
this->get() == target
Exceptions
std::runtime_errorIf no published control block covers the address range of *this.

◆ cycle_member_ptr() [29/29]

template<typename T>
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
cycle_ptr::cycle_member_ptr< T >::cycle_member_ptr ( const cycle_weak_ptr< U > &  ptr)
inlineexplicit

Constructor with automatic ownership detection.

Uses publisher logic to figure out the ownership.

cycle_ptr::allocate_cycle, cycle_ptr::make_cycle, and cycle_ptr::cycle_allocator publish their control block, which is automatically picked up by this contructor.

Postcondition
*this == ptr.lock()
Parameters
ptrInitialize to point at this same object.
Exceptions
std::bad_weak_ptrIf the weak pointer is expired.

Member Function Documentation

◆ get()

template<typename T>
auto cycle_ptr::cycle_member_ptr< T >::get ( ) const -> T*
inline

Returns the raw pointer of this.

Exceptions
std::runtime_errorif the owner of this is expired.

◆ operator *()

template<typename T>
template<bool Enable = !std::is_void_v<T>>
auto cycle_ptr::cycle_member_ptr< T >::operator * ( ) const -> std::enable_if_t<Enable, T>&
inline

Dereference operation.

Only declared if T is not void.

Exceptions
std::runtime_errorif the owner of this is expired.

◆ operator bool()

template<typename T>
cycle_ptr::cycle_member_ptr< T >::operator bool ( ) const
inlineexplicit

Test if this pointer points holds a non-nullptr value.

Returns
get() != nullptr
Exceptions
std::runtime_errorif the owner of this is expired.

◆ operator->()

template<typename T>
template<bool Enable = !std::is_void_v<T>>
auto cycle_ptr::cycle_member_ptr< T >::operator-> ( ) const -> std::enable_if_t<Enable, T>*
inline

Indirection operation.

Only declared if T is not void.

Exceptions
std::runtime_errorif the owner of this is expired.

◆ operator=() [1/7]

template<typename T>
auto cycle_ptr::cycle_member_ptr< T >::operator= ( [[maybe_unused] ] std::nullptr_t  nil) -> cycle_member_ptr&
inline

Assignment operator.

Postcondition
*this == nullptr
Exceptions
std::runtime_errorif the owner of this is expired.

◆ operator=() [2/7]

template<typename T>
auto cycle_ptr::cycle_member_ptr< T >::operator= ( const cycle_member_ptr< T > &  other) -> cycle_member_ptr&
inline

Copy assignment operator.

Postcondition
*this == other
Exceptions
std::runtime_errorif the owner of this is expired.
std::runtime_errorif the owner of other is expired.

◆ operator=() [3/7]

template<typename T>
auto cycle_ptr::cycle_member_ptr< T >::operator= ( cycle_member_ptr< T > &&  other) -> cycle_member_ptr&
inline

Move assignment operator.

Postcondition
*this == original value of other
other == nullptr
Exceptions
std::runtime_errorif the owner of this is expired.
std::runtime_errorif the owner of other is expired.

◆ operator=() [4/7]

template<typename T>
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
auto cycle_ptr::cycle_member_ptr< T >::operator= ( const cycle_member_ptr< U > &  other) -> cycle_member_ptr&
inline

Copy assignment operator.

Postcondition
*this == other
Exceptions
std::runtime_errorif the owner of this is expired.
std::runtime_errorif the owner of other is expired.

◆ operator=() [5/7]

template<typename T>
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
auto cycle_ptr::cycle_member_ptr< T >::operator= ( cycle_member_ptr< U > &&  other) -> cycle_member_ptr&
inline

Move assignment operator.

Postcondition
*this == original value of other
other == nullptr
Exceptions
std::runtime_errorif the owner of this is expired.
std::runtime_errorif the owner of other is expired.

◆ operator=() [6/7]

template<typename T>
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
auto cycle_ptr::cycle_member_ptr< T >::operator= ( const cycle_gptr< U > &  other) -> cycle_member_ptr&
inline

Copy assignment operator.

Postcondition
*this == other
Exceptions
std::runtime_errorif the owner of this is expired.

◆ operator=() [7/7]

template<typename T>
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
auto cycle_ptr::cycle_member_ptr< T >::operator= ( cycle_gptr< U > &&  other) -> cycle_member_ptr&
inline

Move assignment operator.

Postcondition
*this == original value of other
other == nullptr
Exceptions
std::runtime_errorif the owner of this is expired.

◆ reset()

template<typename T>
auto cycle_ptr::cycle_member_ptr< T >::reset ( ) -> void
inline

Clear this pointer.

Postcondition
*this == nullptr
Exceptions
std::runtime_errorif the owner of this is expired.

◆ swap() [1/2]

template<typename T>
auto cycle_ptr::cycle_member_ptr< T >::swap ( cycle_member_ptr< T > &  other) -> void
inline

Swap with other pointer.

Postcondition
*this == original value of other other == original value of *this
Exceptions
std::runtime_errorif the owner of this is expired.
std::runtime_errorif the owner of other is expired.

◆ swap() [2/2]

template<typename T>
auto cycle_ptr::cycle_member_ptr< T >::swap ( cycle_gptr< T > &  other) -> void
inline

Swap with other pointer.

Postcondition
*this == original value of other other == original value of *this
Exceptions
std::runtime_errorif the owner of this is expired.
std::runtime_errorif the owner of other is expired.

Friends And Related Function Documentation

◆ const_pointer_cast()

template<typename T , typename U >
auto const_pointer_cast ( const cycle_ptr::cycle_member_ptr< U > &  r) -> cycle_ptr::cycle_gptr<T>
related

Perform const cast on pointer.

◆ dynamic_pointer_cast()

template<typename T , typename U >
auto dynamic_pointer_cast ( const cycle_ptr::cycle_member_ptr< U > &  r) -> cycle_ptr::cycle_gptr<T>
related

Perform dynamic cast on pointer.

◆ exchange()

template<typename T , typename U = cycle_ptr::cycle_gptr<T>>
auto exchange ( cycle_ptr::cycle_member_ptr< T > &  x,
U &&  y 
)
related

Specialize std::exchange.

Assigns y to x, returning the previous value of x.

Specialization is required, because std::exchange creates a copy of x, which in this case is not copy-constructible.

Returns
cycle_gptr with the original value in x.

◆ operator!=() [1/3]

template<typename T , typename U >
auto operator!= ( const cycle_member_ptr< T > &  x,
const cycle_member_ptr< U > &  y 
) -> bool
related

Inequality comparison.

◆ operator!=() [2/3]

template<typename T >
auto operator!= ( const cycle_member_ptr< T > &  x,
[[maybe_unused] ] std::nullptr_t  y 
) -> bool
related

Inequality comparison.

◆ operator!=() [3/3]

template<typename U >
auto operator!= ( [[maybe_unused] ] std::nullptr_t  x,
const cycle_member_ptr< U > &  y 
) -> bool
related

Inequality comparison.

◆ operator<() [1/3]

template<typename T , typename U >
auto operator< ( const cycle_member_ptr< T > &  x,
const cycle_member_ptr< U > &  y 
) -> bool
related

Less comparison.

◆ operator<() [2/3]

template<typename T >
auto operator< ( const cycle_member_ptr< T > &  x,
[[maybe_unused] ] std::nullptr_t  y 
) -> bool
related

Less comparison.

◆ operator<() [3/3]

template<typename U >
auto operator< ( [[maybe_unused] ] std::nullptr_t  x,
const cycle_member_ptr< U > &  y 
) -> bool
related

Less comparison.

◆ operator<<()

template<typename Char , typename Traits , typename T >
auto operator<< ( std::basic_ostream< Char, Traits > &  out,
const cycle_member_ptr< T > &  ptr 
) -> std::basic_ostream<Char, Traits>&
related

Write pointer to output stream.

◆ operator<=() [1/3]

template<typename T , typename U >
auto operator<= ( const cycle_member_ptr< T > &  x,
const cycle_member_ptr< U > &  y 
) -> bool
related

Less or equal comparison.

◆ operator<=() [2/3]

template<typename T >
auto operator<= ( const cycle_member_ptr< T > &  x,
[[maybe_unused] ] std::nullptr_t  y 
) -> bool
related

Less or equal comparison.

◆ operator<=() [3/3]

template<typename U >
auto operator<= ( [[maybe_unused] ] std::nullptr_t  x,
const cycle_member_ptr< U > &  y 
) -> bool
related

Less or equal comparison.

◆ operator==() [1/3]

template<typename T , typename U >
auto operator== ( const cycle_member_ptr< T > &  x,
const cycle_member_ptr< U > &  y 
) -> bool
related

Equality comparison.

◆ operator==() [2/3]

template<typename T >
auto operator== ( const cycle_member_ptr< T > &  x,
[[maybe_unused] ] std::nullptr_t  y 
) -> bool
related

Equality comparison.

◆ operator==() [3/3]

template<typename U >
auto operator== ( [[maybe_unused] ] std::nullptr_t  x,
const cycle_member_ptr< U > &  y 
) -> bool
related

Equality comparison.

◆ operator>() [1/3]

template<typename T , typename U >
auto operator> ( const cycle_member_ptr< T > &  x,
const cycle_member_ptr< U > &  y 
) -> bool
related

Greater comparison.

◆ operator>() [2/3]

template<typename T >
auto operator> ( const cycle_member_ptr< T > &  x,
[[maybe_unused] ] std::nullptr_t  y 
) -> bool
related

Greater comparison.

◆ operator>() [3/3]

template<typename U >
auto operator> ( [[maybe_unused] ] std::nullptr_t  x,
const cycle_member_ptr< U > &  y 
) -> bool
related

Greater comparison.

◆ operator>=() [1/3]

template<typename T , typename U >
auto operator>= ( const cycle_member_ptr< T > &  x,
const cycle_member_ptr< U > &  y 
) -> bool
related

Greater or equal comparison.

◆ operator>=() [2/3]

template<typename T >
auto operator>= ( const cycle_member_ptr< T > &  x,
[[maybe_unused] ] std::nullptr_t  y 
) -> bool
related

Greater or equal comparison.

◆ operator>=() [3/3]

template<typename U >
auto operator>= ( [[maybe_unused] ] std::nullptr_t  x,
const cycle_member_ptr< U > &  y 
) -> bool
related

Greater or equal comparison.

◆ reinterpret_pointer_cast()

template<typename T , typename U >
auto reinterpret_pointer_cast ( const cycle_ptr::cycle_member_ptr< U > &  r) -> cycle_ptr::cycle_gptr<T>
related

Perform reinterpret cast on pointer.

◆ static_pointer_cast()

template<typename T , typename U >
auto static_pointer_cast ( const cycle_ptr::cycle_member_ptr< U > &  r) -> cycle_ptr::cycle_gptr<T>
related

Perform static cast on pointer.

◆ swap()

template<typename T >
auto swap ( cycle_member_ptr< T > &  x,
cycle_member_ptr< T > &  y 
) -> void
related

Swap two pointers.


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