WPILibC++ 2027.0.0-alpha-2
Loading...
Searching...
No Matches
slp::IntrusiveSharedPtr< T > Class Template Reference

A custom intrusive shared pointer implementation without thread synchronization overhead. More...

#include </home/runner/work/allwpilib/allwpilib/wpimath/src/main/native/thirdparty/sleipnir/include/sleipnir/util/intrusive_shared_ptr.hpp>

Public Member Functions

constexpr IntrusiveSharedPtr () noexcept=default
 Constructs an empty intrusive shared pointer.
 
constexpr IntrusiveSharedPtr (std::nullptr_t) noexcept
 Constructs an empty intrusive shared pointer.
 
constexpr IntrusiveSharedPtr (T *ptr) noexcept
 Constructs an intrusive shared pointer from the given pointer and takes ownership.
 
constexpr ~IntrusiveSharedPtr ()
 
constexpr IntrusiveSharedPtr (const IntrusiveSharedPtr< T > &rhs) noexcept
 Copy constructs from the given intrusive shared pointer.
 
template<typename U >
requires (!std::same_as<T, U> && std::convertible_to<U*, T*>)
constexpr IntrusiveSharedPtr (const IntrusiveSharedPtr< U > &rhs) noexcept
 Copy constructs from the given intrusive shared pointer.
 
constexpr IntrusiveSharedPtr< T > & operator= (const IntrusiveSharedPtr< T > &rhs) noexcept
 Makes a copy of the given intrusive shared pointer.
 
template<typename U >
requires (!std::same_as<T, U> && std::convertible_to<U*, T*>)
constexpr IntrusiveSharedPtr< T > & operator= (const IntrusiveSharedPtr< U > &rhs) noexcept
 Makes a copy of the given intrusive shared pointer.
 
constexpr IntrusiveSharedPtr (IntrusiveSharedPtr< T > &&rhs) noexcept
 Move constructs from the given intrusive shared pointer.
 
template<typename U >
requires (!std::same_as<T, U> && std::convertible_to<U*, T*>)
constexpr IntrusiveSharedPtr (IntrusiveSharedPtr< U > &&rhs) noexcept
 Move constructs from the given intrusive shared pointer.
 
constexpr IntrusiveSharedPtr< T > & operator= (IntrusiveSharedPtr< T > &&rhs) noexcept
 Move assigns from the given intrusive shared pointer.
 
template<typename U >
requires (!std::same_as<T, U> && std::convertible_to<U*, T*>)
constexpr IntrusiveSharedPtr< T > & operator= (IntrusiveSharedPtr< U > &&rhs) noexcept
 Move assigns from the given intrusive shared pointer.
 
constexpr T * get () const noexcept
 Returns the internal pointer.
 
constexpr T & operator* () const noexcept
 Returns the object pointed to by the internal pointer.
 
constexpr T * operator-> () const noexcept
 Returns the internal pointer.
 
constexpr operator bool () const noexcept
 Returns true if the internal pointer isn't nullptr.
 

Friends

template<typename >
class IntrusiveSharedPtr
 
constexpr bool operator== (const IntrusiveSharedPtr< T > &lhs, const IntrusiveSharedPtr< T > &rhs) noexcept
 Returns true if the given intrusive shared pointers point to the same object.
 
constexpr bool operator!= (const IntrusiveSharedPtr< T > &lhs, const IntrusiveSharedPtr< T > &rhs) noexcept
 Returns true if the given intrusive shared pointers point to different objects.
 
constexpr bool operator== (const IntrusiveSharedPtr< T > &lhs, std::nullptr_t) noexcept
 Returns true if the left-hand intrusive shared pointer points to nullptr.
 
constexpr bool operator== (std::nullptr_t, const IntrusiveSharedPtr< T > &rhs) noexcept
 Returns true if the right-hand intrusive shared pointer points to nullptr.
 
constexpr bool operator!= (const IntrusiveSharedPtr< T > &lhs, std::nullptr_t) noexcept
 Returns true if the left-hand intrusive shared pointer doesn't point to nullptr.
 
constexpr bool operator!= (std::nullptr_t, const IntrusiveSharedPtr< T > &rhs) noexcept
 Returns true if the right-hand intrusive shared pointer doesn't point to nullptr.
 

Detailed Description

template<typename T>
class slp::IntrusiveSharedPtr< T >

A custom intrusive shared pointer implementation without thread synchronization overhead.

Types used with this class should have three things:

  1. A zero-initialized public counter variable that serves as the shared pointer's reference count.
  2. A free function void inc_ref_count(T*) that increments the reference count.
  3. A free function void dec_ref_count(T*) that decrements the reference count and deallocates the pointed to object if the reference count reaches zero.
Template Parameters
TThe type of the object to be reference counted.

Constructor & Destructor Documentation

◆ IntrusiveSharedPtr() [1/7]

template<typename T >
slp::IntrusiveSharedPtr< T >::IntrusiveSharedPtr ( )
constexprdefaultnoexcept

Constructs an empty intrusive shared pointer.

◆ IntrusiveSharedPtr() [2/7]

template<typename T >
slp::IntrusiveSharedPtr< T >::IntrusiveSharedPtr ( std::nullptr_t )
inlineconstexprnoexcept

Constructs an empty intrusive shared pointer.

◆ IntrusiveSharedPtr() [3/7]

template<typename T >
slp::IntrusiveSharedPtr< T >::IntrusiveSharedPtr ( T * ptr)
inlineexplicitconstexprnoexcept

Constructs an intrusive shared pointer from the given pointer and takes ownership.

Parameters
ptrThe pointer of which to take ownership.

◆ ~IntrusiveSharedPtr()

template<typename T >
slp::IntrusiveSharedPtr< T >::~IntrusiveSharedPtr ( )
inlineconstexpr

◆ IntrusiveSharedPtr() [4/7]

template<typename T >
slp::IntrusiveSharedPtr< T >::IntrusiveSharedPtr ( const IntrusiveSharedPtr< T > & rhs)
inlineconstexprnoexcept

Copy constructs from the given intrusive shared pointer.

Parameters
rhsThe other intrusive shared pointer.

◆ IntrusiveSharedPtr() [5/7]

template<typename T >
template<typename U >
requires (!std::same_as<T, U> && std::convertible_to<U*, T*>)
slp::IntrusiveSharedPtr< T >::IntrusiveSharedPtr ( const IntrusiveSharedPtr< U > & rhs)
inlineconstexprnoexcept

Copy constructs from the given intrusive shared pointer.

Parameters
rhsThe other intrusive shared pointer.

◆ IntrusiveSharedPtr() [6/7]

template<typename T >
slp::IntrusiveSharedPtr< T >::IntrusiveSharedPtr ( IntrusiveSharedPtr< T > && rhs)
inlineconstexprnoexcept

Move constructs from the given intrusive shared pointer.

Parameters
rhsThe other intrusive shared pointer.

◆ IntrusiveSharedPtr() [7/7]

template<typename T >
template<typename U >
requires (!std::same_as<T, U> && std::convertible_to<U*, T*>)
slp::IntrusiveSharedPtr< T >::IntrusiveSharedPtr ( IntrusiveSharedPtr< U > && rhs)
inlineconstexprnoexcept

Move constructs from the given intrusive shared pointer.

Parameters
rhsThe other intrusive shared pointer.

Member Function Documentation

◆ get()

template<typename T >
T * slp::IntrusiveSharedPtr< T >::get ( ) const
inlineconstexprnoexcept

Returns the internal pointer.

Returns
The internal pointer.

◆ operator bool()

template<typename T >
slp::IntrusiveSharedPtr< T >::operator bool ( ) const
inlineexplicitconstexprnoexcept

Returns true if the internal pointer isn't nullptr.

Returns
True if the internal pointer isn't nullptr.

◆ operator*()

template<typename T >
T & slp::IntrusiveSharedPtr< T >::operator* ( ) const
inlineconstexprnoexcept

Returns the object pointed to by the internal pointer.

Returns
The object pointed to by the internal pointer.

◆ operator->()

template<typename T >
T * slp::IntrusiveSharedPtr< T >::operator-> ( ) const
inlineconstexprnoexcept

Returns the internal pointer.

Returns
The internal pointer.

◆ operator=() [1/4]

template<typename T >
IntrusiveSharedPtr< T > & slp::IntrusiveSharedPtr< T >::operator= ( const IntrusiveSharedPtr< T > & rhs)
inlineconstexprnoexcept

Makes a copy of the given intrusive shared pointer.

Parameters
rhsThe other intrusive shared pointer.
Returns
This intrusive shared pointer.

◆ operator=() [2/4]

template<typename T >
template<typename U >
requires (!std::same_as<T, U> && std::convertible_to<U*, T*>)
IntrusiveSharedPtr< T > & slp::IntrusiveSharedPtr< T >::operator= ( const IntrusiveSharedPtr< U > & rhs)
inlineconstexprnoexcept

Makes a copy of the given intrusive shared pointer.

Parameters
rhsThe other intrusive shared pointer.
Returns
This intrusive shared pointer.

◆ operator=() [3/4]

template<typename T >
IntrusiveSharedPtr< T > & slp::IntrusiveSharedPtr< T >::operator= ( IntrusiveSharedPtr< T > && rhs)
inlineconstexprnoexcept

Move assigns from the given intrusive shared pointer.

Parameters
rhsThe other intrusive shared pointer.
Returns
This intrusive shared pointer.

◆ operator=() [4/4]

template<typename T >
template<typename U >
requires (!std::same_as<T, U> && std::convertible_to<U*, T*>)
IntrusiveSharedPtr< T > & slp::IntrusiveSharedPtr< T >::operator= ( IntrusiveSharedPtr< U > && rhs)
inlineconstexprnoexcept

Move assigns from the given intrusive shared pointer.

Parameters
rhsThe other intrusive shared pointer.
Returns
This intrusive shared pointer.

Friends And Related Symbol Documentation

◆ IntrusiveSharedPtr

template<typename T >
template<typename >
friend class IntrusiveSharedPtr
friend

◆ operator!= [1/3]

template<typename T >
bool operator!= ( const IntrusiveSharedPtr< T > & lhs,
const IntrusiveSharedPtr< T > & rhs )
friend

Returns true if the given intrusive shared pointers point to different objects.

Parameters
lhsThe left-hand side.
rhsThe right-hand side.

◆ operator!= [2/3]

template<typename T >
bool operator!= ( const IntrusiveSharedPtr< T > & lhs,
std::nullptr_t  )
friend

Returns true if the left-hand intrusive shared pointer doesn't point to nullptr.

Parameters
lhsThe left-hand side.

◆ operator!= [3/3]

template<typename T >
bool operator!= ( std::nullptr_t ,
const IntrusiveSharedPtr< T > & rhs )
friend

Returns true if the right-hand intrusive shared pointer doesn't point to nullptr.

Parameters
rhsThe right-hand side.

◆ operator== [1/3]

template<typename T >
bool operator== ( const IntrusiveSharedPtr< T > & lhs,
const IntrusiveSharedPtr< T > & rhs )
friend

Returns true if the given intrusive shared pointers point to the same object.

Parameters
lhsThe left-hand side.
rhsThe right-hand side.

◆ operator== [2/3]

template<typename T >
bool operator== ( const IntrusiveSharedPtr< T > & lhs,
std::nullptr_t  )
friend

Returns true if the left-hand intrusive shared pointer points to nullptr.

Parameters
lhsThe left-hand side.

◆ operator== [3/3]

template<typename T >
bool operator== ( std::nullptr_t ,
const IntrusiveSharedPtr< T > & rhs )
friend

Returns true if the right-hand intrusive shared pointer points to nullptr.

Parameters
rhsThe right-hand side.

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