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

Global (or automatic) scope smart pointer. More...

#include <cycle_ptr.h>

Public Types

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

Public Member Functions

constexpr cycle_gptr () noexcept
 Default constructor. More...
 
constexpr cycle_gptr ([[maybe_unused]] std::nullptr_t nil) noexcept
 Nullptr constructor. More...
 
 cycle_gptr (const cycle_gptr &other) noexcept
 Copy constructor. More...
 
 cycle_gptr (cycle_gptr &&other) noexcept
 Move constructor. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
 cycle_gptr (const cycle_gptr< U > &other) noexcept
 Copy constructor. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
 cycle_gptr (cycle_gptr< U > &&other) noexcept
 Move constructor. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
 cycle_gptr (const cycle_member_ptr< U > &other)
 Copy constructor. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
 cycle_gptr (cycle_member_ptr< U > &&other)
 Move constructor. More...
 
template<typename U >
 cycle_gptr (const cycle_gptr< U > &other, element_type *target) noexcept
 Aliasing constructor. More...
 
template<typename U >
 cycle_gptr (const cycle_member_ptr< U > &other, element_type *target)
 Aliasing constructor. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
 cycle_gptr (const cycle_weak_ptr< U > &other)
 Construct from cycle_weak_ptr. More...
 
auto operator= (const cycle_gptr &other) noexcept -> cycle_gptr &
 Copy assignment. More...
 
auto operator= (cycle_gptr &&other) noexcept -> cycle_gptr &
 Move assignment. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
auto operator= (const cycle_gptr< U > &other) noexcept -> cycle_gptr &
 Copy assignment. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
auto operator= (cycle_gptr< U > &&other) noexcept -> cycle_gptr &
 Move assignment. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
auto operator= (const cycle_member_ptr< U > &other) -> cycle_gptr &
 Copy assignment. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
auto operator= (cycle_member_ptr< U > &&other) -> cycle_gptr &
 Move assignment. More...
 
auto reset () noexcept -> void
 Clear this pointer. More...
 
auto swap (cycle_gptr &other) noexcept -> void
 Swap with other. More...
 
auto swap (cycle_member_ptr< T > &other) -> void
 Swap with other. More...
 
auto get () const noexcept -> T *
 Retrieve address of this pointer.
 
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 noexcept
 Test if this holds a non-nullptr. More...
 
template<typename U >
auto owner_before (const cycle_weak_ptr< U > &other) const noexcept -> bool
 Ownership ordering. More...
 
template<typename U >
auto owner_before (const cycle_gptr< U > &other) const noexcept -> bool
 Ownership ordering. More...
 
template<typename U >
auto owner_before (const cycle_member_ptr< U > &other) const noexcept -> bool
 Ownership ordering. More...
 

Friends

template<typename >
class cycle_member_ptr
 
template<typename >
class cycle_gptr
 
template<typename >
class cycle_weak_ptr
 
class cycle_base
 
template<typename Type , typename Alloc , typename... Args>
auto cycle_ptr::allocate_cycle (Alloc alloc, Args &&... args) -> cycle_gptr< Type >
 

Related Functions

(Note that these are not member functions.)

template<typename T >
auto swap (cycle_member_ptr< T > &x, cycle_gptr< T > &y) noexcept -> void
 Swap two pointers.
 
template<typename T , typename U >
auto operator== (const cycle_gptr< T > &x, const cycle_gptr< U > &y) noexcept -> bool
 Equality comparison. More...
 
template<typename T >
auto operator== (const cycle_gptr< 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_gptr< U > &y) noexcept -> bool
 Equality comparison. More...
 
template<typename T , typename U >
auto operator!= (const cycle_gptr< T > &x, const cycle_gptr< U > &y) noexcept -> bool
 Inequality comparison. More...
 
template<typename T >
auto operator!= (const cycle_gptr< 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_gptr< U > &y) noexcept -> bool
 Inequality comparison. More...
 
template<typename T , typename U >
auto operator< (const cycle_gptr< T > &x, const cycle_gptr< U > &y) noexcept -> bool
 Less comparison. More...
 
template<typename T >
auto operator< (const cycle_gptr< 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_gptr< U > &y) noexcept -> bool
 Less comparison. More...
 
template<typename T , typename U >
auto operator> (const cycle_gptr< T > &x, const cycle_gptr< U > &y) noexcept -> bool
 Greater comparison. More...
 
template<typename T >
auto operator> (const cycle_gptr< 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_gptr< U > &y) noexcept -> bool
 Greater comparison. More...
 
template<typename T , typename U >
auto operator<= (const cycle_gptr< T > &x, const cycle_gptr< U > &y) noexcept -> bool
 Less or equal comparison. More...
 
template<typename T >
auto operator<= (const cycle_gptr< 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_gptr< U > &y) noexcept -> bool
 Less or equal comparison. More...
 
template<typename T , typename U >
auto operator>= (const cycle_gptr< T > &x, const cycle_gptr< U > &y) noexcept -> bool
 Greater or equal comparison. More...
 
template<typename T >
auto operator>= (const cycle_gptr< 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_gptr< U > &y) noexcept -> bool
 Greater or equal comparison. More...
 
template<typename T >
auto swap (cycle_gptr< T > &x, cycle_gptr< T > &y) noexcept -> void
 Swap two pointers. More...
 
template<typename Char , typename Traits , typename T >
auto operator<< (std::basic_ostream< Char, Traits > &out, const cycle_gptr< T > &ptr) -> std::basic_ostream< Char, Traits > &
 Write pointer to output stream. More...
 
template<typename T , typename U >
auto static_pointer_cast (const cycle_ptr::cycle_gptr< 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_gptr< 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_gptr< 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_gptr< U > &r) -> cycle_ptr::cycle_gptr< T >
 Perform reinterpret cast on pointer. More...
 

Detailed Description

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

Global (or automatic) scope smart pointer.

This smart pointer models a reference to a target object, from a globally reachable place, such as a function variable.

Use this pointer in function arguments/body, global scope, or objects not participating in the cycle_ptr graph.

It is smaller and faster than cycle_member_ptr.

Member Typedef Documentation

◆ element_type

template<typename T>
using cycle_ptr::cycle_gptr< T >::element_type = std::remove_extent_t<T>

Element type of this pointer.

◆ weak_type

template<typename T>
using cycle_ptr::cycle_gptr< T >::weak_type = cycle_weak_ptr<T>

Weak pointer equivalent.

Constructor & Destructor Documentation

◆ cycle_gptr() [1/11]

template<typename T>
constexpr cycle_ptr::cycle_gptr< T >::cycle_gptr ( )
inlinenoexcept

Default constructor.

Postcondition
*this == nullptr

◆ cycle_gptr() [2/11]

template<typename T>
constexpr cycle_ptr::cycle_gptr< T >::cycle_gptr ( [[maybe_unused] ] std::nullptr_t  nil)
inlinenoexcept

Nullptr constructor.

Postcondition
*this == nullptr

◆ cycle_gptr() [3/11]

template<typename T>
cycle_ptr::cycle_gptr< T >::cycle_gptr ( const cycle_gptr< T > &  other)
inlinenoexcept

Copy constructor.

Postcondition
*this == other

◆ cycle_gptr() [4/11]

template<typename T>
cycle_ptr::cycle_gptr< T >::cycle_gptr ( cycle_gptr< T > &&  other)
inlinenoexcept

Move constructor.

Postcondition
*this == original value of other
other == nullptr

◆ cycle_gptr() [5/11]

template<typename T>
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
cycle_ptr::cycle_gptr< T >::cycle_gptr ( const cycle_gptr< U > &  other)
inlinenoexcept

Copy constructor.

Postcondition
*this == other

◆ cycle_gptr() [6/11]

template<typename T>
template<typename U , typename = std::enable_if_t<std::is_convertible_v<U*, T*>>>
cycle_ptr::cycle_gptr< T >::cycle_gptr ( cycle_gptr< U > &&  other)
inlinenoexcept

Move constructor.

Postcondition
*this == original value of other
other == nullptr

◆ cycle_gptr() [7/11]

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

Copy constructor.

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

◆ cycle_gptr() [8/11]

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

Move constructor.

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

◆ cycle_gptr() [9/11]

template<typename T>
template<typename U >
cycle_ptr::cycle_gptr< T >::cycle_gptr ( const cycle_gptr< U > &  other,
element_type target 
)
inlinenoexcept

Aliasing constructor.

Postcondition
control block of this == control block of other
this->get() == target

◆ cycle_gptr() [10/11]

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

Aliasing constructor.

Postcondition
control block of this == control block of other
this->get() == target
Exceptions
std::runtime_errorif owner of other is expired.

◆ cycle_gptr() [11/11]

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

Construct from cycle_weak_ptr.

Postcondition
*this == other.lock()
Exceptions
std::bad_weak_ptrif other is expired.

Member Function Documentation

◆ operator *()

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

Dereference operation.

Attention
If *this == nullptr, behaviour is undefined.

◆ operator bool()

template<typename T>
cycle_ptr::cycle_gptr< T >::operator bool ( ) const
inlineexplicitnoexcept

Test if this holds a non-nullptr.

Returns
get() != nullptr.

◆ operator->()

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

Indirection operation.

Attention
If *this == nullptr, behaviour is undefined.

◆ operator=() [1/6]

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

Copy assignment.

Postcondition
*this == other

◆ operator=() [2/6]

template<typename T>
auto cycle_ptr::cycle_gptr< T >::operator= ( cycle_gptr< T > &&  other) -> cycle_gptr&
inlinenoexcept

Move assignment.

Postcondition
*this == original value of other
other == nullptr

◆ operator=() [3/6]

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

Copy assignment.

Postcondition
*this == other

◆ operator=() [4/6]

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

Move assignment.

Postcondition
*this == original value of other
other == nullptr

◆ operator=() [5/6]

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

Copy assignment.

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

◆ operator=() [6/6]

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

Move assignment.

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

◆ owner_before() [1/3]

template<typename T>
template<typename U >
auto cycle_ptr::cycle_gptr< T >::owner_before ( const cycle_weak_ptr< U > &  other) const -> bool
inlinenoexcept

Ownership ordering.

◆ owner_before() [2/3]

template<typename T>
template<typename U >
auto cycle_ptr::cycle_gptr< T >::owner_before ( const cycle_gptr< U > &  other) const -> bool
inlinenoexcept

Ownership ordering.

◆ owner_before() [3/3]

template<typename T>
template<typename U >
auto cycle_ptr::cycle_gptr< T >::owner_before ( const cycle_member_ptr< U > &  other) const -> bool
inlinenoexcept

Ownership ordering.

◆ reset()

template<typename T>
auto cycle_ptr::cycle_gptr< T >::reset ( ) -> void
inlinenoexcept

Clear this pointer.

Postcondition
*this == nullptr

◆ swap() [1/2]

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

Swap with other.

Postcondition
*this == original value of other
other == original value of *this

◆ swap() [2/2]

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

Swap with other.

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

Friends And Related Function Documentation

◆ const_pointer_cast()

template<typename T , typename U >
auto const_pointer_cast ( const cycle_ptr::cycle_gptr< 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_gptr< U > &  r) -> cycle_ptr::cycle_gptr<T>
related

Perform dynamic cast on pointer.

◆ operator!=() [1/3]

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

Inequality comparison.

◆ operator!=() [2/3]

template<typename T >
auto operator!= ( const cycle_gptr< 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_gptr< U > &  y 
) -> bool
related

Inequality comparison.

◆ operator<() [1/3]

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

Less comparison.

◆ operator<() [2/3]

template<typename T >
auto operator< ( const cycle_gptr< 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_gptr< U > &  y 
) -> bool
related

Less comparison.

◆ operator<<()

template<typename Char , typename Traits , typename T >
auto operator<< ( std::basic_ostream< Char, Traits > &  out,
const cycle_gptr< 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_gptr< T > &  x,
const cycle_gptr< U > &  y 
) -> bool
related

Less or equal comparison.

◆ operator<=() [2/3]

template<typename T >
auto operator<= ( const cycle_gptr< 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_gptr< U > &  y 
) -> bool
related

Less or equal comparison.

◆ operator==() [1/3]

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

Equality comparison.

◆ operator==() [2/3]

template<typename T >
auto operator== ( const cycle_gptr< 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_gptr< U > &  y 
) -> bool
related

Equality comparison.

◆ operator>() [1/3]

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

Greater comparison.

◆ operator>() [2/3]

template<typename T >
auto operator> ( const cycle_gptr< 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_gptr< U > &  y 
) -> bool
related

Greater comparison.

◆ operator>=() [1/3]

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

Greater or equal comparison.

◆ operator>=() [2/3]

template<typename T >
auto operator>= ( const cycle_gptr< 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_gptr< U > &  y 
) -> bool
related

Greater or equal comparison.

◆ reinterpret_pointer_cast()

template<typename T , typename U >
auto reinterpret_pointer_cast ( const cycle_ptr::cycle_gptr< 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_gptr< U > &  r) -> cycle_ptr::cycle_gptr<T>
related

Perform static cast on pointer.

◆ swap()

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

Swap two pointers.


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