kblib 0.2.3
General utilities library for modern C++
kblib::cond_ptr< T, Deleter > Class Template Reference

#include <kblib/memory.h>

Inheritance diagram for kblib::cond_ptr< T, Deleter >:
Collaboration diagram for kblib::cond_ptr< T, Deleter >:

Public Types

using pointer = detail_memory::filter_deleter_pointer_t< Deleter, T >
 
using element_type = T
 
using deleter_type = Deleter
 
using unique = std::unique_ptr< T, Deleter >
 

Public Member Functions

 cond_ptr () noexcept=default
 
 cond_ptr (std::nullptr_t) noexcept
 
 cond_ptr (T *p, bool owner=false, std::decay_t< Deleter > del={}) noexcept
 
 cond_ptr (T *p, std::decay_t< Deleter > del) noexcept
 
 cond_ptr (unique &&p) noexcept
 
 cond_ptr (const cond_ptr &other)=delete
 
 cond_ptr (cond_ptr &&other) noexcept
 
auto operator= (const cond_ptr &rhs) &-> cond_ptr &=delete
 
auto operator= (cond_ptr &&rhs) &noexcept -> cond_ptr &
 
auto operator= (unique &&rhs) -> cond_ptr &
 
auto to_unique () &&noexcept -> unique
 Transfers ownership to a unique_ptr if possible. If *this is not owning, returns nullptr. More...
 
 operator unique () &&noexcept
 
 ~cond_ptr () noexcept
 
auto weak () const &noexcept -> cond_ptr
 
auto owns () const noexcept -> bool
 
auto release () &noexcept -> T *
 
auto get_deleter () noexcept -> Deleter &
 
auto get_deleter () const noexcept -> const Deleter &
 
auto reset (T *p=nullptr, bool owner=false, std::decay_t< Deleter > del={}) &noexcept -> void
 
auto reset (T *p, std::decay_t< Deleter > del={}) &noexcept -> void
 
auto swap (cond_ptr &other) noexcept(fakestd::is_nothrow_swappable< Deleter >::value) -> void
 
auto get () &noexcept -> T *
 
auto get () const &noexcept -> const T *
 
 operator bool () const noexcept
 
auto operator* () &noexcept -> T &
 
auto operator* () const &noexcept -> const T &
 
auto operator-> () &noexcept -> T *
 
auto operator-> () const &noexcept -> const T *
 

Static Public Member Functions

static auto adopt (T *p) noexcept -> cond_ptr
 
static auto adopt (T *p, deleter_type del) noexcept -> cond_ptr
 

Friends

constexpr auto operator== (const cond_ptr &lhs, const cond_ptr &rhs) noexcept -> bool
 
constexpr auto operator== (const unique &lhs, const cond_ptr &rhs) noexcept -> bool
 
constexpr auto operator== (const cond_ptr &lhs, const unique &rhs) noexcept -> bool
 

Detailed Description

template<typename T, typename Deleter = std::default_delete<T>>
class kblib::cond_ptr< T, Deleter >

Definition at line 422 of file memory.h.

Member Typedef Documentation

◆ deleter_type

template<typename T , typename Deleter = std::default_delete<T>>
using kblib::cond_ptr< T, Deleter >::deleter_type = Deleter

Definition at line 428 of file memory.h.

◆ element_type

template<typename T , typename Deleter = std::default_delete<T>>
using kblib::cond_ptr< T, Deleter >::element_type = T

Definition at line 427 of file memory.h.

◆ pointer

template<typename T , typename Deleter = std::default_delete<T>>
using kblib::cond_ptr< T, Deleter >::pointer = detail_memory::filter_deleter_pointer_t<Deleter, T>

Definition at line 426 of file memory.h.

◆ unique

template<typename T , typename Deleter = std::default_delete<T>>
using kblib::cond_ptr< T, Deleter >::unique = std::unique_ptr<T, Deleter>

Definition at line 435 of file memory.h.

Constructor & Destructor Documentation

◆ cond_ptr() [1/7]

template<typename T , typename Deleter = std::default_delete<T>>
kblib::cond_ptr< T, Deleter >::cond_ptr ( )
defaultnoexcept

◆ cond_ptr() [2/7]

template<typename T , typename Deleter = std::default_delete<T>>
kblib::cond_ptr< T, Deleter >::cond_ptr ( std::nullptr_t  )
inlinenoexcept

Definition at line 438 of file memory.h.

◆ cond_ptr() [3/7]

template<typename T , typename Deleter = std::default_delete<T>>
kblib::cond_ptr< T, Deleter >::cond_ptr ( T *  p,
bool  owner = false,
std::decay_t< Deleter >  del = {} 
)
inlineexplicitnoexcept

Definition at line 440 of file memory.h.

◆ cond_ptr() [4/7]

template<typename T , typename Deleter = std::default_delete<T>>
kblib::cond_ptr< T, Deleter >::cond_ptr ( T *  p,
std::decay_t< Deleter >  del 
)
inlineexplicitnoexcept

Definition at line 445 of file memory.h.

◆ cond_ptr() [5/7]

template<typename T , typename Deleter = std::default_delete<T>>
kblib::cond_ptr< T, Deleter >::cond_ptr ( unique &&  p)
inlinenoexcept

Definition at line 449 of file memory.h.

◆ cond_ptr() [6/7]

template<typename T , typename Deleter = std::default_delete<T>>
kblib::cond_ptr< T, Deleter >::cond_ptr ( const cond_ptr< T, Deleter > &  other)
delete

◆ cond_ptr() [7/7]

template<typename T , typename Deleter = std::default_delete<T>>
kblib::cond_ptr< T, Deleter >::cond_ptr ( cond_ptr< T, Deleter > &&  other)
inlinenoexcept

Definition at line 457 of file memory.h.

◆ ~cond_ptr()

template<typename T , typename Deleter = std::default_delete<T>>
kblib::cond_ptr< T, Deleter >::~cond_ptr ( )
inlinenoexcept

Definition at line 517 of file memory.h.

Member Function Documentation

◆ adopt() [1/2]

template<typename T , typename Deleter = std::default_delete<T>>
static auto kblib::cond_ptr< T, Deleter >::adopt ( T *  p) -> cond_ptr
inlinestaticnoexcept

Definition at line 462 of file memory.h.

◆ adopt() [2/2]

template<typename T , typename Deleter = std::default_delete<T>>
static auto kblib::cond_ptr< T, Deleter >::adopt ( T *  p,
deleter_type  del 
) -> cond_ptr
inlinestaticnoexcept

Definition at line 465 of file memory.h.

◆ get() [1/2]

template<typename T , typename Deleter = std::default_delete<T>>
auto kblib::cond_ptr< T, Deleter >::get ( ) & -> T*
inlinenoexcept

Definition at line 567 of file memory.h.

◆ get() [2/2]

template<typename T , typename Deleter = std::default_delete<T>>
auto kblib::cond_ptr< T, Deleter >::get ( ) const & -> const T*
inlinenoexcept

Definition at line 569 of file memory.h.

◆ get_deleter() [1/2]

template<typename T , typename Deleter = std::default_delete<T>>
auto kblib::cond_ptr< T, Deleter >::get_deleter ( ) const -> const Deleter&
inlinenoexcept

Definition at line 537 of file memory.h.

◆ get_deleter() [2/2]

template<typename T , typename Deleter = std::default_delete<T>>
auto kblib::cond_ptr< T, Deleter >::get_deleter ( ) -> Deleter&
inlinenoexcept

Definition at line 533 of file memory.h.

◆ operator bool()

template<typename T , typename Deleter = std::default_delete<T>>
kblib::cond_ptr< T, Deleter >::operator bool ( ) const
inlineexplicitnoexcept

Definition at line 571 of file memory.h.

◆ operator unique()

template<typename T , typename Deleter = std::default_delete<T>>
kblib::cond_ptr< T, Deleter >::operator unique ( ) &&
inlineexplicitnoexcept

Definition at line 513 of file memory.h.

◆ operator*() [1/2]

template<typename T , typename Deleter = std::default_delete<T>>
auto kblib::cond_ptr< T, Deleter >::operator* ( ) & -> T&
inlinenoexcept

Definition at line 573 of file memory.h.

◆ operator*() [2/2]

template<typename T , typename Deleter = std::default_delete<T>>
auto kblib::cond_ptr< T, Deleter >::operator* ( ) const & -> const T&
inlinenoexcept

Definition at line 575 of file memory.h.

◆ operator->() [1/2]

template<typename T , typename Deleter = std::default_delete<T>>
auto kblib::cond_ptr< T, Deleter >::operator-> ( ) & -> T*
inlinenoexcept

Definition at line 579 of file memory.h.

◆ operator->() [2/2]

template<typename T , typename Deleter = std::default_delete<T>>
auto kblib::cond_ptr< T, Deleter >::operator-> ( ) const & -> const T*
inlinenoexcept

Definition at line 581 of file memory.h.

◆ operator=() [1/3]

template<typename T , typename Deleter = std::default_delete<T>>
auto kblib::cond_ptr< T, Deleter >::operator= ( cond_ptr< T, Deleter > &&  rhs) & -> cond_ptr&
inlinenoexcept

Definition at line 479 of file memory.h.

◆ operator=() [2/3]

template<typename T , typename Deleter = std::default_delete<T>>
auto kblib::cond_ptr< T, Deleter >::operator= ( const cond_ptr< T, Deleter > &  rhs) & -> cond_ptr &=delete
delete

◆ operator=() [3/3]

template<typename T , typename Deleter = std::default_delete<T>>
auto kblib::cond_ptr< T, Deleter >::operator= ( unique &&  rhs) -> cond_ptr&
inline

Definition at line 488 of file memory.h.

◆ owns()

template<typename T , typename Deleter = std::default_delete<T>>
auto kblib::cond_ptr< T, Deleter >::owns ( ) const -> bool
inlinenoexcept

Definition at line 527 of file memory.h.

◆ release()

template<typename T , typename Deleter = std::default_delete<T>>
auto kblib::cond_ptr< T, Deleter >::release ( ) & -> T*
inlinenoexcept

Definition at line 528 of file memory.h.

◆ reset() [1/2]

template<typename T , typename Deleter = std::default_delete<T>>
auto kblib::cond_ptr< T, Deleter >::reset ( T *  p,
std::decay_t< Deleter >  del = {} 
) & -> void
inlinenoexcept

Definition at line 550 of file memory.h.

◆ reset() [2/2]

template<typename T , typename Deleter = std::default_delete<T>>
auto kblib::cond_ptr< T, Deleter >::reset ( T *  p = nullptr,
bool  owner = false,
std::decay_t< Deleter >  del = {} 
) & -> void
inlinenoexcept

Definition at line 541 of file memory.h.

◆ swap()

template<typename T , typename Deleter = std::default_delete<T>>
auto kblib::cond_ptr< T, Deleter >::swap ( cond_ptr< T, Deleter > &  other) -> void
inlinenoexcept

Definition at line 559 of file memory.h.

◆ to_unique()

template<typename T , typename Deleter = std::default_delete<T>>
auto kblib::cond_ptr< T, Deleter >::to_unique ( ) && -> unique
inlinenoexcept

Transfers ownership to a unique_ptr if possible. If *this is not owning, returns nullptr.

Postcondition
If ownership was transferred, *this is null. Otherwise, does nothing.
Returns
std::unique_ptr<T, Deleter> Either a pointer which owns what *this owned, or a null pointer.

Definition at line 505 of file memory.h.

◆ weak()

template<typename T , typename Deleter = std::default_delete<T>>
auto kblib::cond_ptr< T, Deleter >::weak ( ) const & -> cond_ptr
inlinenoexcept

Definition at line 523 of file memory.h.

Friends And Related Function Documentation

◆ operator== [1/3]

template<typename T , typename Deleter = std::default_delete<T>>
constexpr auto operator== ( const cond_ptr< T, Deleter > &  lhs,
const cond_ptr< T, Deleter > &  rhs 
) -> bool
friend

Definition at line 585 of file memory.h.

◆ operator== [2/3]

template<typename T , typename Deleter = std::default_delete<T>>
constexpr auto operator== ( const cond_ptr< T, Deleter > &  lhs,
const unique rhs 
) -> bool
friend

Definition at line 595 of file memory.h.

◆ operator== [3/3]

template<typename T , typename Deleter = std::default_delete<T>>
constexpr auto operator== ( const unique lhs,
const cond_ptr< T, Deleter > &  rhs 
) -> bool
friend

Definition at line 590 of file memory.h.


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