rstd 0.1.0
Loading...
Searching...
No Matches
alloc::rc::Rc< T > Class Template Referencefinalexport
module rstd.alloc

A single-threaded reference-counting pointer, analogous to Rust's Rc<T>. More...

Public Member Functions

 Rc ()
 Creates an empty Rc that does not point to any allocation.
 
 Rc (const Rc &other) noexcept(noexp)
 Copy constructs an Rc, incrementing the strong reference count.
 
 Rc (T *p)
 Constructs an Rc from a raw pointer with the default deleter.
 
template<typename Deleter >
 Rc (T *p, Deleter &&d)
 Constructs an Rc from a raw pointer with a custom deleter.
 
template<typename Deleter , typename Allocator >
 Rc (T *p, Deleter &&d, Allocator alloc)
 Constructs an Rc from a raw pointer with a custom deleter and allocator.
 
auto downgrade () const -> Weak< T >
 Creates a Weak pointer to the same allocation.
 
auto clone () const noexcept(noexp) -> Rc
 Creates a new Rc pointer to the same allocation, incrementing the strong count.
 
void swap (Rc &other) noexcept
 Swaps the inner pointers of two Rcs.
 

Detailed Description

template<typename T>
class alloc::rc::Rc< T >

A single-threaded reference-counting pointer, analogous to Rust's Rc<T>.

Template Parameters
TThe type of the value managed by reference counting.

Constructor & Destructor Documentation

◆ Rc() [1/3]

template<typename T >
alloc::rc::Rc< T >::Rc ( T * p)
inlineexplicit

Constructs an Rc from a raw pointer with the default deleter.

Parameters
pThe raw pointer to take ownership of.

◆ Rc() [2/3]

template<typename T >
template<typename Deleter >
alloc::rc::Rc< T >::Rc ( T * p,
Deleter && d )
inline

Constructs an Rc from a raw pointer with a custom deleter.

Template Parameters
DeleterThe type of the deleter callable.
Parameters
pThe raw pointer to take ownership of.
dThe deleter to invoke when the value is dropped.

◆ Rc() [3/3]

template<typename T >
template<typename Deleter , typename Allocator >
alloc::rc::Rc< T >::Rc ( T * p,
Deleter && d,
Allocator alloc )
inline

Constructs an Rc from a raw pointer with a custom deleter and allocator.

Template Parameters
DeleterThe type of the deleter callable.
AllocatorThe type of the allocator.
Parameters
pThe raw pointer to take ownership of.
dThe deleter to invoke when the value is dropped.
allocThe allocator used for the control block.

Member Function Documentation

◆ clone()

template<typename T >
auto alloc::rc::Rc< T >::clone ( ) const -> Rc
inlinenoexcept

Creates a new Rc pointer to the same allocation, incrementing the strong count.

Returns
A cloned Rc.

◆ downgrade()

template<typename T >
auto alloc::rc::Rc< T >::downgrade ( ) const -> Weak<T>
inline

Creates a Weak pointer to the same allocation.

Returns
A Weak<T> that does not contribute to the strong count.

◆ swap()

template<typename T >
void alloc::rc::Rc< T >::swap ( Rc< T > & other)
inlinenoexcept

Swaps the inner pointers of two Rcs.

Parameters
otherThe other Rc to swap with.

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