MySQL 8.3.0
Source Code Documentation
memory::Unique_ptr< T, A > Class Template Reference

Smart pointer to hold a unique pointer to a heap allocated memory of type T, constructed using a specific allocator. More...

#include <unique_ptr.h>

Public Types

using type = typename std::remove_extent< T >::type
 
using pointer = type *
 
using reference = type &
 

Public Member Functions

template<typename D = T, typename B = A, std::enable_if_t< std::is_same< B, std::nullptr_t >::value > * = nullptr>
 Unique_ptr ()
 Default class constructor, only to be used with no specific allocator. More...
 
template<typename D = T, typename B = A, std::enable_if_t<!std::is_same< B, std::nullptr_t >::value > * = nullptr>
 Unique_ptr (A &alloc)
 Class constructor, to be used with specific allocators, passing the allocator object to be used. More...
 
template<typename D = T, typename B = A, std::enable_if_t<!std::is_same< B, std::nullptr_t >::value &&std::is_array< D >::value > * = nullptr>
 Unique_ptr (A &alloc, size_t size)
 Class constructor, to be used with specific allocators and when T is an array type, passing the allocator object to be used and the size of the array. More...
 
template<typename D = T, typename B = A, std::enable_if_t< std::is_same< B, std::nullptr_t >::value &&std::is_array< D >::value > * = nullptr>
 Unique_ptr (size_t size)
 Class constructor, to be used with no specific allocators and when T is an array type, passing the allocator object to be used and the size of the array. More...
 
template<typename... Args, typename D = T, typename B = A, std::enable_if_t<!std::is_same< B, std::nullptr_t >::value &&!std::is_array< D >::value > * = nullptr>
 Unique_ptr (A &alloc, Args &&... args)
 Class constructor, to be used with specific allocators and when T is not an array type, passing the allocator object to be used and the parameters to be used with T object constructor. More...
 
template<typename... Args, typename D = T, typename B = A, std::enable_if_t< std::is_same< B, std::nullptr_t >::value &&!std::is_array< D >::value > * = nullptr>
 Unique_ptr (Args &&... args)
 Class constructor, to be used with no specific allocators and when T is not an array type, passing the parameters to be used with T object constructor. More...
 
 Unique_ptr (Unique_ptr< T, A > const &rhs)=delete
 
 Unique_ptr (Unique_ptr< T, A > &&rhs)
 Move constructor. More...
 
virtual ~Unique_ptr ()
 Destructor for the class. More...
 
Unique_ptr< T, A > & operator= (Unique_ptr< T, A > const &rhs)=delete
 
Unique_ptr< T, A > & operator= (Unique_ptr< T, A > &&rhs)
 Move operator. More...
 
template<typename D = T, std::enable_if_t<!std::is_array< D >::value > * = nullptr>
pointer operator-> () const
 Arrow operator to access the underlying object of type T. More...
 
reference operator* () const
 Star operator to access the underlying object of type T. More...
 
template<typename D = T, std::enable_if_t< std::is_array< D >::value > * = nullptr>
reference operator[] (size_t index) const
 Subscript operator, to access an array element when T is of array type. More...
 
 operator bool () const
 Casting operator to bool. More...
 
template<typename B = A, std::enable_if_t< std::is_same< B, std::nullptr_t >::value > * = nullptr>
pointer release ()
 Releases the ownership of the underlying allocated memory and returns a pointer to the beginning of that memory. More...
 
template<typename B = A, std::enable_if_t<!std::is_same< B, std::nullptr_t >::value > * = nullptr>
pointer release ()
 Releases the ownership of the underlying allocated memory and returns a pointer to the beginning of that memory. More...
 
pointer get () const
 Returns a pointer to the underlying allocated memory. More...
 
size_t size () const
 The size of the memory allocated, in bytes. More...
 
template<typename D = T, typename B = A, std::enable_if_t< std::is_array< D >::value &&std::is_same< B, std::nullptr_t >::value > * = nullptr>
Unique_ptr< T, A > & reserve (size_t new_size)
 Will resize the allocated memory to new_size. More...
 
template<typename D = T, typename B = A, std::enable_if_t< std::is_array< D >::value &&!std::is_same< B, std::nullptr_t >::value > * = nullptr>
Unique_ptr< T, A > & reserve (size_t new_size)
 Will resize the allocated memory to new_size. More...
 
A & allocator () const
 Returns the used allocator instance, if any. More...
 
template<typename D , std::enable_if_t<!std::is_array< D >::value > * >
memory::Unique_ptr< T, A >::pointer operator-> () const
 
template<typename D , std::enable_if_t< std::is_array< D >::value > * >
memory::Unique_ptr< T, A >::reference operator[] (size_t index) const
 
template<typename B , std::enable_if_t< std::is_same< B, std::nullptr_t >::value > * >
memory::Unique_ptr< T, A >::pointer release ()
 
template<typename D , typename B , std::enable_if_t< std::is_array< D >::value &&std::is_same< B, std::nullptr_t >::value > * >
memory::Unique_ptr< T, A > & reserve (size_t new_size)
 
template<typename D , std::enable_if_t< std::is_array< D >::value > * >
memory::Unique_ptr< T, A >::pointer clone () const
 

Private Member Functions

void reset ()
 Clears the underlying pointer and size. More...
 
template<typename D = T, typename B = A, std::enable_if_t< std::is_same< B, std::nullptr_t >::value &&std::is_array< D >::value > * = nullptr>
void destroy ()
 Deallocates the underlying allocated memory. More...
 
template<typename D = T, typename B = A, std::enable_if_t< std::is_same< B, std::nullptr_t >::value &&!std::is_array< D >::value > * = nullptr>
void destroy ()
 Deallocates the underlying allocated memory. More...
 
template<typename D = T, typename B = A, std::enable_if_t<!std::is_same< B, std::nullptr_t >::value &&std::is_array< D >::value > * = nullptr>
void destroy ()
 Deallocates the underlying allocated memory. More...
 
template<typename D = T, typename B = A, std::enable_if_t<!std::is_same< B, std::nullptr_t >::value &&!std::is_array< D >::value > * = nullptr>
void destroy ()
 Deallocates the underlying allocated memory. More...
 
template<typename D = T, std::enable_if_t< std::is_array< D >::value > * = nullptr>
pointer clone () const
 Clones the underlying memory and returns a pointer to the clone memory. More...
 
template<typename D = T, std::enable_if_t<!std::is_array< D >::value > * = nullptr>
pointer clone () const
 Clones the underlying memory and returns a pointer to the clone memory. More...
 

Private Attributes

pointer m_underlying {nullptr}
 The pointer to the underlying allocated memory
More...
 
memory::Ref_ptr< A > m_allocator
 The allocator to be used to allocate memory. More...
 
size_t m_size {0}
 The size of the allocated memory. More...
 

Detailed Description

template<typename T, typename A = std::nullptr_t>
class memory::Unique_ptr< T, A >

Smart pointer to hold a unique pointer to a heap allocated memory of type T, constructed using a specific allocator.

Template parameters are as follows:

  • T is the type of the pointer to allocate. It may be an array type.
  • A the allocator to use. If none is passed, std::nullptr_t is passed and regular new and delete are used to construct the memory.

Member Typedef Documentation

◆ pointer

template<typename T , typename A = std::nullptr_t>
using memory::Unique_ptr< T, A >::pointer = type *

◆ reference

template<typename T , typename A = std::nullptr_t>
using memory::Unique_ptr< T, A >::reference = type &

◆ type

template<typename T , typename A = std::nullptr_t>
using memory::Unique_ptr< T, A >::type = typename std::remove_extent<T>::type

Constructor & Destructor Documentation

◆ Unique_ptr() [1/8]

template<typename T , typename A >
template<typename D , typename B , std::enable_if_t< std::is_same< B, std::nullptr_t >::value > * >
memory::Unique_ptr< T, A >::Unique_ptr

Default class constructor, only to be used with no specific allocator.

◆ Unique_ptr() [2/8]

template<typename T , typename A >
template<typename D , typename B , std::enable_if_t<!std::is_same< B, std::nullptr_t >::value > * >
memory::Unique_ptr< T, A >::Unique_ptr ( A &  alloc)

Class constructor, to be used with specific allocators, passing the allocator object to be used.

Parameters
allocThe allocator instance to be used.

◆ Unique_ptr() [3/8]

template<typename T , typename A >
template<typename D , typename B , std::enable_if_t<!std::is_same< B, std::nullptr_t >::value &&std::is_array< D >::value > * >
memory::Unique_ptr< T, A >::Unique_ptr ( A &  alloc,
size_t  size 
)

Class constructor, to be used with specific allocators and when T is an array type, passing the allocator object to be used and the size of the array.

Parameters
allocThe allocator instance to be used.
sizeThe size of the array to allocate.

◆ Unique_ptr() [4/8]

template<typename T , typename A >
template<typename D , typename B , std::enable_if_t< std::is_same< B, std::nullptr_t >::value &&std::is_array< D >::value > * >
memory::Unique_ptr< T, A >::Unique_ptr ( size_t  size)

Class constructor, to be used with no specific allocators and when T is an array type, passing the allocator object to be used and the size of the array.

Parameters
sizeThe size of the array to allocate.

◆ Unique_ptr() [5/8]

template<typename T , typename A >
template<typename... Args, typename D , typename B , std::enable_if_t<!std::is_same< B, std::nullptr_t >::value &&!std::is_array< D >::value > * >
memory::Unique_ptr< T, A >::Unique_ptr ( A &  alloc,
Args &&...  args 
)

Class constructor, to be used with specific allocators and when T is not an array type, passing the allocator object to be used and the parameters to be used with T object constructor.

Parameters
allocThe allocator instance to be used.
argsThe parameters to be used with T object constructor.

◆ Unique_ptr() [6/8]

template<typename T , typename A >
template<typename... Args, typename D , typename B , std::enable_if_t< std::is_same< B, std::nullptr_t >::value &&!std::is_array< D >::value > * >
memory::Unique_ptr< T, A >::Unique_ptr ( Args &&...  args)

Class constructor, to be used with no specific allocators and when T is not an array type, passing the parameters to be used with T object constructor.

Parameters
argsThe parameters to be used with T object constructor.

◆ Unique_ptr() [7/8]

template<typename T , typename A = std::nullptr_t>
memory::Unique_ptr< T, A >::Unique_ptr ( Unique_ptr< T, A > const &  rhs)
delete

◆ Unique_ptr() [8/8]

template<typename T , typename A >
memory::Unique_ptr< T, A >::Unique_ptr ( memory::Unique_ptr< T, A > &&  rhs)

Move constructor.

Parameters
rhsThe object to move data from.

◆ ~Unique_ptr()

template<typename T , typename A >
memory::Unique_ptr< T, A >::~Unique_ptr
virtual

Destructor for the class.

Member Function Documentation

◆ allocator()

template<typename T , typename A >
A & memory::Unique_ptr< T, A >::allocator

Returns the used allocator instance, if any.

Returns
The reference to the allocator object.

◆ clone() [1/3]

template<typename T , typename A = std::nullptr_t>
template<typename D = T, std::enable_if_t< std::is_array< D >::value > * = nullptr>
pointer memory::Unique_ptr< T, A >::clone ( ) const
private

Clones the underlying memory and returns a pointer to the clone memory.

Returns
A pointer to the cloned underlying memory.

◆ clone() [2/3]

template<typename T , typename A = std::nullptr_t>
template<typename D = T, std::enable_if_t<!std::is_array< D >::value > * = nullptr>
pointer memory::Unique_ptr< T, A >::clone ( ) const
private

Clones the underlying memory and returns a pointer to the clone memory.

Returns
A pointer to the cloned underlying memory.

◆ clone() [3/3]

template<typename T , typename A >
template<typename D , std::enable_if_t<!std::is_array< D >::value > * >
memory::Unique_ptr< T, A >::pointer memory::Unique_ptr< T, A >::clone

◆ destroy() [1/4]

template<typename T , typename A >
template<typename D , typename B , std::enable_if_t<!std::is_same< B, std::nullptr_t >::value &&!std::is_array< D >::value > * >
void memory::Unique_ptr< T, A >::destroy
private

Deallocates the underlying allocated memory.

◆ destroy() [2/4]

template<typename T , typename A = std::nullptr_t>
template<typename D = T, typename B = A, std::enable_if_t< std::is_same< B, std::nullptr_t >::value &&!std::is_array< D >::value > * = nullptr>
void memory::Unique_ptr< T, A >::destroy ( )
private

Deallocates the underlying allocated memory.

◆ destroy() [3/4]

template<typename T , typename A = std::nullptr_t>
template<typename D = T, typename B = A, std::enable_if_t<!std::is_same< B, std::nullptr_t >::value &&std::is_array< D >::value > * = nullptr>
void memory::Unique_ptr< T, A >::destroy ( )
private

Deallocates the underlying allocated memory.

◆ destroy() [4/4]

template<typename T , typename A = std::nullptr_t>
template<typename D = T, typename B = A, std::enable_if_t<!std::is_same< B, std::nullptr_t >::value &&!std::is_array< D >::value > * = nullptr>
void memory::Unique_ptr< T, A >::destroy ( )
private

Deallocates the underlying allocated memory.

◆ get()

template<typename T , typename A >
memory::Unique_ptr< T, A >::pointer memory::Unique_ptr< T, A >::get

Returns a pointer to the underlying allocated memory.

Returns
A pointer to the underlying allocated memory

◆ operator bool()

template<typename T , typename A >
memory::Unique_ptr< T, A >::operator bool

Casting operator to bool.

Returns
true if the underlying pointer is instantiated, false otherwise.

◆ operator*()

template<typename T , typename A >
memory::Unique_ptr< T, A >::reference memory::Unique_ptr< T, A >::operator*

Star operator to access the underlying object of type T.

Returns
A reference to the underlying object of type T.

◆ operator->() [1/2]

template<typename T , typename A = std::nullptr_t>
template<typename D = T, std::enable_if_t<!std::is_array< D >::value > * = nullptr>
pointer memory::Unique_ptr< T, A >::operator-> ( ) const

Arrow operator to access the underlying object of type T.

Returns
A pointer to the underlying object of type T.

◆ operator->() [2/2]

template<typename T , typename A = std::nullptr_t>
template<typename D , std::enable_if_t<!std::is_array< D >::value > * >
memory::Unique_ptr< T, A >::pointer memory::Unique_ptr< T, A >::operator-> ( ) const

◆ operator=() [1/2]

template<typename T , typename A >
memory::Unique_ptr< T, A > & memory::Unique_ptr< T, A >::operator= ( memory::Unique_ptr< T, A > &&  rhs)

Move operator.

Parameters
rhsThe object to move data from.

◆ operator=() [2/2]

template<typename T , typename A = std::nullptr_t>
Unique_ptr< T, A > & memory::Unique_ptr< T, A >::operator= ( Unique_ptr< T, A > const &  rhs)
delete

◆ operator[]() [1/2]

template<typename T , typename A = std::nullptr_t>
template<typename D = T, std::enable_if_t< std::is_array< D >::value > * = nullptr>
reference memory::Unique_ptr< T, A >::operator[] ( size_t  index) const

Subscript operator, to access an array element when T is of array type.

Parameters
indexThe index of the element to retrieve the value for.
Returns
A reference to the value stored at index.

◆ operator[]() [2/2]

template<typename T , typename A = std::nullptr_t>
template<typename D , std::enable_if_t< std::is_array< D >::value > * >
memory::Unique_ptr< T, A >::reference memory::Unique_ptr< T, A >::operator[] ( size_t  index) const

◆ release() [1/3]

template<typename T , typename A = std::nullptr_t>
template<typename B = A, std::enable_if_t< std::is_same< B, std::nullptr_t >::value > * = nullptr>
pointer memory::Unique_ptr< T, A >::release ( )

Releases the ownership of the underlying allocated memory and returns a pointer to the beginning of that memory.

This smart pointer will no longer manage the underlying memory.

Returns
the pointer to the allocated and no longer managed memory.

◆ release() [2/3]

template<typename T , typename A = std::nullptr_t>
template<typename B = A, std::enable_if_t<!std::is_same< B, std::nullptr_t >::value > * = nullptr>
pointer memory::Unique_ptr< T, A >::release ( )

Releases the ownership of the underlying allocated memory and returns a pointer to the beginning of that memory.

This smart pointer will no longer manage the underlying memory.

Returns
the pointer to the allocated and no longer managed memory.

◆ release() [3/3]

template<typename T , typename A >
template<typename B , std::enable_if_t<!std::is_same< B, std::nullptr_t >::value > * >
memory::Unique_ptr< T, A >::pointer memory::Unique_ptr< T, A >::release

◆ reserve() [1/3]

template<typename T , typename A = std::nullptr_t>
template<typename D = T, typename B = A, std::enable_if_t< std::is_array< D >::value &&std::is_same< B, std::nullptr_t >::value > * = nullptr>
Unique_ptr< T, A > & memory::Unique_ptr< T, A >::reserve ( size_t  new_size)

Will resize the allocated memory to new_size.

If the configure allocator supports this operation, the allocator is used. If not, a new memory chunk is allocated and the memory is copied.

Parameters
new_sizeThe new desired size for the memory.
Returns
The reference to this object, for chaining purposed.

◆ reserve() [2/3]

template<typename T , typename A = std::nullptr_t>
template<typename D = T, typename B = A, std::enable_if_t< std::is_array< D >::value &&!std::is_same< B, std::nullptr_t >::value > * = nullptr>
Unique_ptr< T, A > & memory::Unique_ptr< T, A >::reserve ( size_t  new_size)

Will resize the allocated memory to new_size.

If the configure allocator supports this operation, the allocator is used. If not, a new memory chunk is allocated and the memory is copied.

Parameters
new_sizeThe new desired size for the memory.
Returns
The reference to this object, for chaining purposed.

◆ reserve() [3/3]

template<typename T , typename A >
template<typename D , typename B , std::enable_if_t< std::is_array< D >::value &&!std::is_same< B, std::nullptr_t >::value > * >
memory::Unique_ptr< T, A > & memory::Unique_ptr< T, A >::reserve ( size_t  new_size)

◆ reset()

template<typename T , typename A >
void memory::Unique_ptr< T, A >::reset ( void  )
private

Clears the underlying pointer and size.

◆ size()

template<typename T , typename A >
size_t memory::Unique_ptr< T, A >::size

The size of the memory allocated, in bytes.

Returns
The size of the memory allocated, in bytes

Member Data Documentation

◆ m_allocator

template<typename T , typename A = std::nullptr_t>
memory::Ref_ptr<A> memory::Unique_ptr< T, A >::m_allocator
private

The allocator to be used to allocate memory.

◆ m_size

template<typename T , typename A = std::nullptr_t>
size_t memory::Unique_ptr< T, A >::m_size {0}
private

The size of the allocated memory.

◆ m_underlying

template<typename T , typename A = std::nullptr_t>
pointer memory::Unique_ptr< T, A >::m_underlying {nullptr}
private

The pointer to the underlying allocated memory


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