xentara-utils v1.2.1
Xentara utilities library
Loading...
Searching...
No Matches
xentara::utils::tools::UnownedPointer< Element, Deleter > Class Template Reference

A non-owning pointer that is interface compatible with std::unique_ptr. More...

#include <tools/UnownedPointer.hpp>

Public Types

using pointer = typename std::unique_ptr< Element, Deleter >::pointer
 A type alias for a raw pointer.
 
using element_type = typename std::unique_ptr< Element, Deleter >::element_type
 A type alias for the element type.
 

Public Member Functions

constexpr UnownedPointer () noexcept=default
 Constructor for an empty pointer.
 
constexpr UnownedPointer (const UnownedPointer &) noexcept=default
 Copy constructor.
 
template<typename RelatedElement , typename RelatedDeleter >
requires std::is_constructible_v<std::unique_ptr<Element, Deleter>, std::unique_ptr<RelatedElement, RelatedDeleter> &&>
constexpr UnownedPointer (const UnownedPointer< RelatedElement, RelatedDeleter > &value) noexcept
 Constructor that sets the value from a related pointer.
 
constexpr UnownedPointer (const std::unique_ptr< Element, Deleter > &value) noexcept
 Constructor that sets the value from an std::unique_ptr.
 
template<typename RelatedElement , typename RelatedDeleter >
requires std::is_constructible_v<std::unique_ptr<Element, Deleter>, std::unique_ptr<RelatedElement, RelatedDeleter> &&>
constexpr UnownedPointer (const std::unique_ptr< RelatedElement, RelatedDeleter > &value) noexcept
 Constructor that sets the value from a related std::unique_ptr.
 
constexpr UnownedPointer (pointer value) noexcept
 Constructor that sets the value from a raw pointer.
 
constexpr UnownedPointer (std::nullptr_t) noexcept
 Constructor that sets the value to an empty pointer.
 
constexpr auto operator= (const UnownedPointer &) noexcept -> UnownedPointer &=default
 Assignment operator.
 
template<typename RelatedElement , typename RelatedDeleter >
requires std::is_constructible_v<std::unique_ptr<Element, Deleter>, std::unique_ptr<RelatedElement, RelatedDeleter> &&>
constexpr auto operator= (const UnownedPointer< RelatedElement, RelatedDeleter > &value) noexcept -> UnownedPointer &
 Assignment operator that sets the value from a related pointer.
 
constexpr auto operator= (const std::unique_ptr< Element, Deleter > &value) noexcept -> UnownedPointer &
 Assignment operator that sets the value from an std::unique_ptr.
 
template<typename RelatedElement , typename RelatedDeleter >
requires std::is_constructible_v<std::unique_ptr<Element, Deleter>, std::unique_ptr<RelatedElement, RelatedDeleter> &&>
constexpr auto operator= (const std::unique_ptr< RelatedElement, RelatedDeleter > &value) noexcept -> UnownedPointer &
 Assignment operator that sets the value from a related std::unique_ptr.
 
constexpr auto operator= (std::nullptr_t) noexcept -> UnownedPointer &
 Assignment operator that sets the value to an empty pointer.
 
auto operator* () const noexcept(noexcept(*std::declval< pointer >())) -> typename std::add_lvalue_reference_t< Element >
 Access to the pointed-to object.
 
auto operator-> () const noexcept -> pointer
 Access to members of the pointed-to object.
 
 operator bool () const noexcept
 Checks whether the value is non-empty.
 
auto get () const noexcept -> pointer
 Gets the current value.
 
auto reset (pointer value=pointer()) noexcept -> void
 Sets a new value.
 
auto swap (UnownedPointer &other) noexcept -> void
 Swaps the value with another unowned pointer.
 

Related Symbols

(Note that these are not member symbols.)

template<typename LhsElement , typename LhsDeleter , typename RhsElement , typename RhsDeleter >
constexpr auto operator== (const UnownedPointer< LhsElement, LhsDeleter > &lhs, const UnownedPointer< RhsElement, RhsDeleter > &rhs) -> bool
 Comparison between two unowned pointers.
 
template<typename LhsElement , typename LhsDeleter , typename RhsElement , typename RhsDeleter >
constexpr auto operator== (const UnownedPointer< LhsElement, LhsDeleter > &lhs, const std::unique_ptr< RhsElement, RhsDeleter > &rhs) -> bool
 Comparison between an unowned pointer and an std::unique_ptr.
 
template<typename Element , typename Deleter >
constexpr auto operator== (const UnownedPointer< Element, Deleter > &lhs, std::nullptr_t) -> bool
 Comparison between an unowned pointer and a null pointer.
 
template<typename LhsElement , typename LhsDeleter , typename RhsElement , typename RhsDeleter >
constexpr auto operator (const UnownedPointer< LhsElement, LhsDeleter > &lhs, const UnownedPointer< RhsElement, RhsDeleter > &rhs) -> auto
 Tree-way comparison between two unowned pointers.
 
template<typename LhsElement , typename LhsDeleter , typename RhsElement , typename RhsDeleter >
constexpr auto operator (const UnownedPointer< LhsElement, LhsDeleter > &lhs, const std::unique_ptr< RhsElement, RhsDeleter > &rhs) -> auto
 Tree-way comparison between an unowned pointer and an std::unique_ptr.
 
template<typename Element , typename Deleter >
constexpr auto operator (const UnownedPointer< Element, Deleter > &lhs, std::nullptr_t) -> auto
 Tree-way comparison between an unowned pointer and a null pointer.
 
template<typename Character , typename Traits , typename Element , typename Deleter >
auto operator<< (std::basic_ostream< Character, Traits > &stream, const UnownedPointer< Element, Deleter > &pointer) -> std::basic_ostream< Character, Traits > &
 Stream insertion operator.
 
template<typename Element , typename Deleter >
auto swap (UnownedPointer< Element, Deleter > &lhs, UnownedPointer< Element, Deleter > &rhs) noexcept -> void
 Swaps two unowned pointers.
 

Detailed Description

template<typename Element, typename Deleter = std::default_delete<Element>>
class xentara::utils::tools::UnownedPointer< Element, Deleter >

A non-owning pointer that is interface compatible with std::unique_ptr.

This class wraps a regular pointer into an object whose interface is (mostly) compatible with std::unique_ptr. It can be used in situations where an object is not owned by the pointer, but using a raw Element * is not desirable. This class is used as the return type of atomic::UniquePointer::load(), for example.

Template Parameters
ElementThe element the pointer holds
DeleterThe deleter used by the compatible std::unique_ptr. This class only used the deleter to determine the correct type for the pointer and element_type type aliases.

Member Typedef Documentation

◆ element_type

template<typename Element , typename Deleter = std::default_delete<Element>>
using xentara::utils::tools::UnownedPointer< Element, Deleter >::element_type = typename std::unique_ptr<Element, Deleter>::element_type

A type alias for the element type.

◆ pointer

template<typename Element , typename Deleter = std::default_delete<Element>>
using xentara::utils::tools::UnownedPointer< Element, Deleter >::pointer = typename std::unique_ptr<Element, Deleter>::pointer

A type alias for a raw pointer.

Constructor & Destructor Documentation

◆ UnownedPointer() [1/7]

template<typename Element , typename Deleter = std::default_delete<Element>>
constexpr xentara::utils::tools::UnownedPointer< Element, Deleter >::UnownedPointer ( )
constexprdefaultnoexcept

Constructor for an empty pointer.

◆ UnownedPointer() [2/7]

template<typename Element , typename Deleter = std::default_delete<Element>>
constexpr xentara::utils::tools::UnownedPointer< Element, Deleter >::UnownedPointer ( const UnownedPointer< Element, Deleter > &  )
constexprdefaultnoexcept

Copy constructor.

◆ UnownedPointer() [3/7]

template<typename Element , typename Deleter = std::default_delete<Element>>
template<typename RelatedElement , typename RelatedDeleter >
requires std::is_constructible_v<std::unique_ptr<Element, Deleter>, std::unique_ptr<RelatedElement, RelatedDeleter> &&>
constexpr xentara::utils::tools::UnownedPointer< Element, Deleter >::UnownedPointer ( const UnownedPointer< RelatedElement, RelatedDeleter > &  value)
constexprnoexcept

Constructor that sets the value from a related pointer.

◆ UnownedPointer() [4/7]

template<typename Element , typename Deleter = std::default_delete<Element>>
constexpr xentara::utils::tools::UnownedPointer< Element, Deleter >::UnownedPointer ( const std::unique_ptr< Element, Deleter > &  value)
constexprnoexcept

Constructor that sets the value from an std::unique_ptr.

◆ UnownedPointer() [5/7]

template<typename Element , typename Deleter = std::default_delete<Element>>
template<typename RelatedElement , typename RelatedDeleter >
requires std::is_constructible_v<std::unique_ptr<Element, Deleter>, std::unique_ptr<RelatedElement, RelatedDeleter> &&>
constexpr xentara::utils::tools::UnownedPointer< Element, Deleter >::UnownedPointer ( const std::unique_ptr< RelatedElement, RelatedDeleter > &  value)
constexprnoexcept

Constructor that sets the value from a related std::unique_ptr.

◆ UnownedPointer() [6/7]

template<typename Element , typename Deleter = std::default_delete<Element>>
constexpr xentara::utils::tools::UnownedPointer< Element, Deleter >::UnownedPointer ( pointer  value)
explicitconstexprnoexcept

Constructor that sets the value from a raw pointer.

◆ UnownedPointer() [7/7]

template<typename Element , typename Deleter = std::default_delete<Element>>
constexpr xentara::utils::tools::UnownedPointer< Element, Deleter >::UnownedPointer ( std::nullptr_t  )
constexprnoexcept

Constructor that sets the value to an empty pointer.

Member Function Documentation

◆ get()

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::tools::UnownedPointer< Element, Deleter >::get ( ) const -> pointer
noexcept

Gets the current value.

◆ operator bool()

template<typename Element , typename Deleter = std::default_delete<Element>>
xentara::utils::tools::UnownedPointer< Element, Deleter >::operator bool ( ) const
explicitnoexcept

Checks whether the value is non-empty.

Returns
Return true if the object contains a pointer, or false is it is empty (contains a null pointer).

◆ operator*()

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::tools::UnownedPointer< Element, Deleter >::operator* ( ) const -> typename std::add_lvalue_reference_t<Element>
noexcept

Access to the pointed-to object.

Precondition
This function must not be called on an empty pointer

◆ operator->()

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::tools::UnownedPointer< Element, Deleter >::operator-> ( ) const -> pointer
noexcept

Access to members of the pointed-to object.

◆ operator=() [1/5]

template<typename Element , typename Deleter = std::default_delete<Element>>
constexpr auto xentara::utils::tools::UnownedPointer< Element, Deleter >::operator= ( const std::unique_ptr< Element, Deleter > &  value) -> UnownedPointer &
constexprnoexcept

Assignment operator that sets the value from an std::unique_ptr.

◆ operator=() [2/5]

template<typename Element , typename Deleter = std::default_delete<Element>>
template<typename RelatedElement , typename RelatedDeleter >
requires std::is_constructible_v<std::unique_ptr<Element, Deleter>, std::unique_ptr<RelatedElement, RelatedDeleter> &&>
constexpr auto xentara::utils::tools::UnownedPointer< Element, Deleter >::operator= ( const std::unique_ptr< RelatedElement, RelatedDeleter > &  value) -> UnownedPointer &
constexprnoexcept

Assignment operator that sets the value from a related std::unique_ptr.

◆ operator=() [3/5]

template<typename Element , typename Deleter = std::default_delete<Element>>
constexpr auto xentara::utils::tools::UnownedPointer< Element, Deleter >::operator= ( const UnownedPointer< Element, Deleter > &  ) -> UnownedPointer &=default
constexprdefaultnoexcept

Assignment operator.

◆ operator=() [4/5]

template<typename Element , typename Deleter = std::default_delete<Element>>
template<typename RelatedElement , typename RelatedDeleter >
requires std::is_constructible_v<std::unique_ptr<Element, Deleter>, std::unique_ptr<RelatedElement, RelatedDeleter> &&>
constexpr auto xentara::utils::tools::UnownedPointer< Element, Deleter >::operator= ( const UnownedPointer< RelatedElement, RelatedDeleter > &  value) -> UnownedPointer &
constexprnoexcept

Assignment operator that sets the value from a related pointer.

◆ operator=() [5/5]

template<typename Element , typename Deleter = std::default_delete<Element>>
constexpr auto xentara::utils::tools::UnownedPointer< Element, Deleter >::operator= ( std::nullptr_t  ) -> UnownedPointer &
constexprnoexcept

Assignment operator that sets the value to an empty pointer.

◆ reset()

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::tools::UnownedPointer< Element, Deleter >::reset ( pointer  value = pointer()) -> void
noexcept

Sets a new value.

◆ swap()

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::tools::UnownedPointer< Element, Deleter >::swap ( UnownedPointer< Element, Deleter > &  other) -> void
noexcept

Swaps the value with another unowned pointer.

Friends And Related Symbol Documentation

◆ operator() [1/3]

template<typename Element , typename Deleter >
constexpr auto operator<=> ( const UnownedPointer< Element, Deleter > &  lhs,
std::nullptr_t   
) -> auto
related

Tree-way comparison between an unowned pointer and a null pointer.

◆ operator() [2/3]

template<typename LhsElement , typename LhsDeleter , typename RhsElement , typename RhsDeleter >
constexpr auto operator<=> ( const UnownedPointer< LhsElement, LhsDeleter > &  lhs,
const std::unique_ptr< RhsElement, RhsDeleter > &  rhs 
) -> auto
related

Tree-way comparison between an unowned pointer and an std::unique_ptr.

◆ operator() [3/3]

template<typename LhsElement , typename LhsDeleter , typename RhsElement , typename RhsDeleter >
constexpr auto operator<=> ( const UnownedPointer< LhsElement, LhsDeleter > &  lhs,
const UnownedPointer< RhsElement, RhsDeleter > &  rhs 
) -> auto
related

Tree-way comparison between two unowned pointers.

◆ operator<<()

template<typename Character , typename Traits , typename Element , typename Deleter >
auto operator<< ( std::basic_ostream< Character, Traits > &  stream,
const UnownedPointer< Element, Deleter > &  pointer 
) -> std::basic_ostream<Character, Traits> &
related

Stream insertion operator.

This operator insert the pointer (not the pointed-to value) into the stream.

See also
operator<<(std::basic_ostream &, const std::unique_ptr &)

◆ operator==() [1/3]

template<typename Element , typename Deleter >
constexpr auto operator== ( const UnownedPointer< Element, Deleter > &  lhs,
std::nullptr_t   
) -> bool
related

Comparison between an unowned pointer and a null pointer.

◆ operator==() [2/3]

template<typename LhsElement , typename LhsDeleter , typename RhsElement , typename RhsDeleter >
constexpr auto operator== ( const UnownedPointer< LhsElement, LhsDeleter > &  lhs,
const std::unique_ptr< RhsElement, RhsDeleter > &  rhs 
) -> bool
related

Comparison between an unowned pointer and an std::unique_ptr.

◆ operator==() [3/3]

template<typename LhsElement , typename LhsDeleter , typename RhsElement , typename RhsDeleter >
constexpr auto operator== ( const UnownedPointer< LhsElement, LhsDeleter > &  lhs,
const UnownedPointer< RhsElement, RhsDeleter > &  rhs 
) -> bool
related

Comparison between two unowned pointers.

◆ swap()

template<typename Element , typename Deleter >
auto swap ( UnownedPointer< Element, Deleter > &  lhs,
UnownedPointer< Element, Deleter > &  rhs 
) -> void
related

Swaps two unowned pointers.