3.7.0
Freundlich's C++ toolkit
Public Types | Public Member Functions
fcppt::unique_ptr< Type, Deleter > Class Template Reference

Detailed Description

template<typename Type, typename Deleter>
class fcppt::unique_ptr< Type, Deleter >

A simpler unique_ptr that shouldn't be used as a null pointer.

std::unique_ptr can easily be used as a null pointer because it has a default constructor and also a reset function. Null pointers should always be handled by optional references instead (see fcppt.optional). While it is not possible to completely forbid unique pointers that are null, this class makes it harder to do so. Unique pointers that have been moved from may still be null because a unique pointer must track its ownership status. Make sure not to access such pointers.

Public Types

using element_type = Type
 
using pointer = element_type *
 
using deleter_type = Deleter
 

Public Member Functions

 unique_ptr (pointer) noexcept
 Constructs a unique_ptr from a pointer. This pointer should not be equal to nullptr. More...
 
 unique_ptr (unique_ptr &&) noexcept
 
unique_ptroperator= (unique_ptr &&) noexcept
 
 ~unique_ptr ()
 
std::add_lvalue_reference_t< Type > operator* () const noexcept
 
pointer operator-> () const noexcept
 
pointer get_pointer () const noexcept
 
pointer release_ownership () noexcept
 Releases ownerhsip. More...
 
 unique_ptr (std::unique_ptr< Type > &&) noexcept
 For implementation purposes only. More...
 

Member Typedef Documentation

◆ deleter_type

template<typename Type , typename Deleter >
using fcppt::unique_ptr< Type, Deleter >::deleter_type = Deleter

◆ element_type

template<typename Type , typename Deleter >
using fcppt::unique_ptr< Type, Deleter >::element_type = Type

◆ pointer

template<typename Type , typename Deleter >
using fcppt::unique_ptr< Type, Deleter >::pointer = element_type *

Constructor & Destructor Documentation

◆ unique_ptr() [1/3]

template<typename Type , typename Deleter >
fcppt::unique_ptr< Type, Deleter >::unique_ptr ( pointer  )
explicitnoexcept

Constructs a unique_ptr from a pointer. This pointer should not be equal to nullptr.

◆ unique_ptr() [2/3]

template<typename Type , typename Deleter >
fcppt::unique_ptr< Type, Deleter >::unique_ptr ( unique_ptr< Type, Deleter > &&  )
noexcept

◆ ~unique_ptr()

template<typename Type , typename Deleter >
fcppt::unique_ptr< Type, Deleter >::~unique_ptr ( )

◆ unique_ptr() [3/3]

template<typename Type , typename Deleter >
fcppt::unique_ptr< Type, Deleter >::unique_ptr ( std::unique_ptr< Type > &&  )
explicitnoexcept

For implementation purposes only.

Member Function Documentation

◆ get_pointer()

template<typename Type , typename Deleter >
pointer fcppt::unique_ptr< Type, Deleter >::get_pointer ( ) const
noexcept

◆ operator*()

template<typename Type , typename Deleter >
std::add_lvalue_reference_t<Type> fcppt::unique_ptr< Type, Deleter >::operator* ( ) const
noexcept

◆ operator->()

template<typename Type , typename Deleter >
pointer fcppt::unique_ptr< Type, Deleter >::operator-> ( ) const
noexcept

◆ operator=()

template<typename Type , typename Deleter >
unique_ptr& fcppt::unique_ptr< Type, Deleter >::operator= ( unique_ptr< Type, Deleter > &&  )
noexcept

◆ release_ownership()

template<typename Type , typename Deleter >
pointer fcppt::unique_ptr< Type, Deleter >::release_ownership ( )
noexcept

Releases ownerhsip.

This can be used to move the pointer to another class that takes over ownership. Use this with extreme caution.