tenno 0.1.0
Loading...
Searching...
No Matches
tenno::shared_ptr< T, Deleter, Alloc > Class Template Reference

A shared pointer. More...

#include <memory.hpp>

Data Structures

struct  control_block
 

Public Types

using element_type = T
 The type of the object to point to.
 

Public Member Functions

 shared_ptr () noexcept
 Default constructor.
 
 shared_ptr (T *ptr)
 Construct a new shared pointer object.
 
 shared_ptr (T *ptr, Deleter deleter)
 Construct a new shared pointer object.
 
 shared_ptr (T *ptr, Deleter deleter, Alloc alloc)
 Construct a new shared pointer object.
 
 shared_ptr (const shared_ptr &other) noexcept
 Copy constructor.
 
 shared_ptr (shared_ptr &&other) noexcept
 Move constructor.
 
 ~shared_ptr ()
 Destructor.
 
shared_ptroperator= (shared_ptr &&other) noexcept
 Move assignment operator.
 
shared_ptroperator= (const shared_ptr &other) noexcept
 Copy assignment operator.
 
void reset () noexcept
 Reset the shared pointer.
 
void reset (T *ptr) noexcept
 Reset the shared pointer to point to the object managed by the control block cb.
 
void reset (T *ptr, Deleter deleter) noexcept
 Reset the shared pointer to point to the object managed by the control block cb.
 
void reset (T *ptr, Deleter deleter, Alloc alloc) noexcept
 Reset the shared pointer to point to the object managed by the control block cb.
 
void swap (shared_ptr &other) noexcept
 Swap the shared pointer with another shared pointer.
 
T * get () const noexcept
 Get the object pointed to by the shared pointer.
 
T & operator* () const noexcept
 Dereference operator.
 
T * operator-> () const noexcept
 Member access operator.
 
auto & operator[] (tenno::size index) const noexcept
 Array access operator.
 
long use_count () const noexcept
 Get the number of shared pointers pointing to the object.
 
 operator bool () const noexcept
 Check if the shared pointer is empty.
 
bool owner_before (const shared_ptr &other) const noexcept
 Stored value ordering.
 
bool owner_equal (const shared_ptr &other) const noexcept
 Stored value equality.
 

Data Fields

friend control_block
 

Friends

class tenno::weak_ptr< T >
 
template<class Y , class... Args>
std::enable_if<!std::is_array< Y >::value, shared_ptr< Y > >::type make_shared (Args &&... args)
 Create a shared pointer with the given arguments.
 
template<class Y >
shared_ptr< Y > make_shared ()
 Default initialize a shared pointer.
 
template<class Y >
std::enable_if< std::is_array< Y >::value, shared_ptr< Y > >::type make_shared (tenno::size n)
 

Detailed Description

template<class T, class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
class tenno::shared_ptr< T, Deleter, Alloc >

A shared pointer.

Template Parameters
TThe type of the object to point to

Definition at line 88 of file memory.hpp.

Member Typedef Documentation

◆ element_type

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
using tenno::shared_ptr< T, Deleter, Alloc >::element_type = T

The type of the object to point to.

Definition at line 94 of file memory.hpp.

Constructor & Destructor Documentation

◆ shared_ptr() [1/6]

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
tenno::shared_ptr< T, Deleter, Alloc >::shared_ptr ( )
inlinenoexcept

Default constructor.

Definition at line 128 of file memory.hpp.

◆ shared_ptr() [2/6]

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
tenno::shared_ptr< T, Deleter, Alloc >::shared_ptr ( T * ptr)
inline

Construct a new shared pointer object.

Parameters
ptrThe object to point to

Definition at line 137 of file memory.hpp.

◆ shared_ptr() [3/6]

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
tenno::shared_ptr< T, Deleter, Alloc >::shared_ptr ( T * ptr,
Deleter deleter )
inline

Construct a new shared pointer object.

Parameters
ptrThe object to point to
deleterThe deleter to use to delete the object

Definition at line 158 of file memory.hpp.

◆ shared_ptr() [4/6]

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
tenno::shared_ptr< T, Deleter, Alloc >::shared_ptr ( T * ptr,
Deleter deleter,
Alloc alloc )
inline

Construct a new shared pointer object.

Parameters
ptrThe object to point to
deleterThe deleter to use to delete the object
allocatorThe allocator to use to allocate the control block

Definition at line 180 of file memory.hpp.

◆ shared_ptr() [5/6]

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
tenno::shared_ptr< T, Deleter, Alloc >::shared_ptr ( const shared_ptr< T, Deleter, Alloc > & other)
inlinenoexcept

Copy constructor.

Parameters
otherThe shared pointer to copy

Definition at line 200 of file memory.hpp.

◆ shared_ptr() [6/6]

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
tenno::shared_ptr< T, Deleter, Alloc >::shared_ptr ( shared_ptr< T, Deleter, Alloc > && other)
inlinenoexcept

Move constructor.

Parameters
otherThe shared pointer to move

Definition at line 212 of file memory.hpp.

◆ ~shared_ptr()

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
tenno::shared_ptr< T, Deleter, Alloc >::~shared_ptr ( )
inline

Destructor.

Definition at line 222 of file memory.hpp.

Member Function Documentation

◆ get()

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
T * tenno::shared_ptr< T, Deleter, Alloc >::get ( ) const
inlinenoexcept

Get the object pointed to by the shared pointer.

Returns
T* The object pointed to by the shared pointer

Definition at line 427 of file memory.hpp.

◆ operator bool()

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
tenno::shared_ptr< T, Deleter, Alloc >::operator bool ( ) const
inlineexplicitnoexcept

Check if the shared pointer is empty.

Returns
true If the shared pointer is empty
false If the shared pointer is not empty

Definition at line 481 of file memory.hpp.

◆ operator*()

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
T & tenno::shared_ptr< T, Deleter, Alloc >::operator* ( ) const
inlinenoexcept

Dereference operator.

Returns
T& The object pointed to by the shared pointer

Definition at line 437 of file memory.hpp.

◆ operator->()

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
T * tenno::shared_ptr< T, Deleter, Alloc >::operator-> ( ) const
inlinenoexcept

Member access operator.

Returns
T* The object pointed to by the shared pointer

Definition at line 447 of file memory.hpp.

◆ operator=() [1/2]

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
shared_ptr & tenno::shared_ptr< T, Deleter, Alloc >::operator= ( const shared_ptr< T, Deleter, Alloc > & other)
inlinenoexcept

Copy assignment operator.

Parameters
otherThe shared pointer to copy
Returns
shared_ptr& The copied shared pointer

Definition at line 259 of file memory.hpp.

◆ operator=() [2/2]

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
shared_ptr & tenno::shared_ptr< T, Deleter, Alloc >::operator= ( shared_ptr< T, Deleter, Alloc > && other)
inlinenoexcept

Move assignment operator.

Parameters
otherThe shared pointer to move
Returns
shared_ptr& The moved shared pointer

Definition at line 243 of file memory.hpp.

◆ operator[]()

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
auto & tenno::shared_ptr< T, Deleter, Alloc >::operator[] ( tenno::size index) const
inlinenoexcept

Array access operator.

Parameters
indexThe index of the element to access
Returns
T& The element at the given index

Definition at line 458 of file memory.hpp.

◆ owner_before()

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
bool tenno::shared_ptr< T, Deleter, Alloc >::owner_before ( const shared_ptr< T, Deleter, Alloc > & other) const
inlinenoexcept

Stored value ordering.

Parameters
otherThe shared pointer to compare with
Returns
true If the shared pointer is before the other shared pointer
false If the shared pointer is after the other shared pointer

Definition at line 493 of file memory.hpp.

◆ owner_equal()

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
bool tenno::shared_ptr< T, Deleter, Alloc >::owner_equal ( const shared_ptr< T, Deleter, Alloc > & other) const
inlinenoexcept

Stored value equality.

Parameters
otherThe shared pointer to compare with
Returns
true If the shared pointer is equal to the other shared pointer
false If the shared pointer is not equal to the other shared pointer

Definition at line 506 of file memory.hpp.

◆ reset() [1/4]

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
void tenno::shared_ptr< T, Deleter, Alloc >::reset ( )
inlinenoexcept

Reset the shared pointer.

Definition at line 285 of file memory.hpp.

◆ reset() [2/4]

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
void tenno::shared_ptr< T, Deleter, Alloc >::reset ( T * ptr)
inlinenoexcept

Reset the shared pointer to point to the object managed by the control block cb.

Parameters
cbThe control block to manage the object

Definition at line 309 of file memory.hpp.

◆ reset() [3/4]

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
void tenno::shared_ptr< T, Deleter, Alloc >::reset ( T * ptr,
Deleter deleter )
inlinenoexcept

Reset the shared pointer to point to the object managed by the control block cb.

Parameters
cbThe control block to manage the object
deleterThe deleter to use to delete the object

Definition at line 343 of file memory.hpp.

◆ reset() [4/4]

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
void tenno::shared_ptr< T, Deleter, Alloc >::reset ( T * ptr,
Deleter deleter,
Alloc alloc )
inlinenoexcept

Reset the shared pointer to point to the object managed by the control block cb.

Parameters
cbThe control block to manage the object
deleterThe deleter to use to delete the object
allocatorThe allocator to use to allocate the object

Definition at line 378 of file memory.hpp.

◆ swap()

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
void tenno::shared_ptr< T, Deleter, Alloc >::swap ( shared_ptr< T, Deleter, Alloc > & other)
inlinenoexcept

Swap the shared pointer with another shared pointer.

Parameters
otherThe shared pointer to swap with

Definition at line 410 of file memory.hpp.

◆ use_count()

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
long tenno::shared_ptr< T, Deleter, Alloc >::use_count ( ) const
inlinenoexcept

Get the number of shared pointers pointing to the object.

Returns
long The number of shared pointers pointing to the object

Definition at line 468 of file memory.hpp.

Friends And Related Symbol Documentation

◆ make_shared [1/3]

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
template<class Y >
shared_ptr< Y > make_shared ( )
friend

Default initialize a shared pointer.

Template Parameters
TThe type of the object to create
Returns
shared_ptr<T> The shared pointer to the object

Definition at line 1061 of file memory.hpp.

◆ make_shared [2/3]

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
template<class Y , class... Args>
std::enable_if<!std::is_array< Y >::value, shared_ptr< Y > >::type make_shared ( Args &&... args)
friend

Create a shared pointer with the given arguments.

Template Parameters
TThe type of the object to create
ArgsThe type of the arguments to pass to the constructor
Parameters
argsThe arguments to pass to the constructor
Returns
shared_ptr<T> The shared pointer to the object
Note
Make shared takes care of the allocation of the object, while the shared pointer takes care of the allocation and deallocation of the internal control block, as well as the deallocation of the object.
The object must accept variadic arguments in the constructor

Definition at line 1017 of file memory.hpp.

◆ make_shared [3/3]

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
template<class Y >
std::enable_if< std::is_array< Y >::value, shared_ptr< Y > >::type make_shared ( tenno::size n)
friend

Definition at line 1037 of file memory.hpp.

◆ tenno::weak_ptr< T >

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
friend class tenno::weak_ptr< T >
friend

Definition at line 115 of file memory.hpp.

Field Documentation

◆ control_block

template<class T , class Deleter = tenno::default_delete<T>, class Alloc = tenno::allocator<T>>
friend tenno::shared_ptr< T, Deleter, Alloc >::control_block

Definition at line 115 of file memory.hpp.


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