Simple-Utility v2.3.1
Loading...
Searching...
No Matches
sl::unique_handle< T, TDeleteAction > Class Template Reference

This type models some kind of std::optional behaviour but resets itself on move operations. More...

#include <unique_handle.hpp>

Public Types

using value_type = T
 Type of the stored value.
 
using delete_action_type = TDeleteAction
 Type of the used delete action.
 

Public Member Functions

constexpr unique_handle () noexcept=default
 Default constructor. The value will be in an uninitialized stated and the delete action gets default constructed.
 
constexpr ~unique_handle () noexcept
 Destruct. Does invoke the delete action if the value is in an initialized state.
 
SL_UNIQUE_HANDLE_FULL_CONSTEXPR unique_handle (unique_handle &&other) noexcept(std::is_nothrow_move_constructible_v< T > &&std::is_nothrow_copy_constructible_v< TDeleteAction >)
 Move constructor, which relocates the ownership of the value to the target and resets the source. Delete actions will be copied.
 
SL_UNIQUE_HANDLE_FULL_CONSTEXPR unique_handleoperator= (unique_handle &&other) noexcept(std::is_nothrow_move_constructible_v< T > &&std::is_nothrow_move_assignable_v< T > &&std::is_nothrow_copy_constructible_v< TDeleteAction > &&std::is_nothrow_copy_assignable_v< TDeleteAction >)
 Move assignment, which relocates the ownership of the value to the target and resets the source. Delete actions will be copied.
 
constexpr void swap (unique_handle &other) noexcept(std::is_nothrow_move_constructible_v< T > &&std::is_nothrow_swappable_v< T > &&std::is_nothrow_move_constructible_v< TDeleteAction > &&std::is_nothrow_swappable_v< TDeleteAction >)
 Swaps the target and the source in a more efficient way.
 
 unique_handle (const unique_handle &)=delete
 Explicitly deleted copy constructor.
 
unique_handleoperator= (const unique_handle &)=delete
 Explicitly deleted copy assignment.
 
constexpr unique_handle (nullhandle_t, const delete_action_type &deleteAction=delete_action_type()) noexcept
 Explicitly does not initialize the value. This overload is mainly used for convenience when returning a nullhandle.
 
SL_UNIQUE_HANDLE_FULL_CONSTEXPR unique_handleoperator= (nullhandle_t) noexcept
 Explicitly resets the value and invokes the delete action if value was initialized.
 
constexpr unique_handle (const delete_action_type &deleteAction) noexcept
 Constructor overload for explicitly providing a delete action.
 
template<concepts::initializes< T > T2>
requires concepts::not_same_as<std::remove_cvref_t<T2>, unique_handle> && concepts::not_same_as<std::remove_cvref_t<T2>, nullhandle_t>
!std ::convertible_to< T2 &&, T > constexpr unique_handle (T2 &&value, const delete_action_type &deleteAction=delete_action_type{})
 Constructor overload for initializing the value.
 
template<concepts::assignable_to< T & > T2>
requires concepts::not_same_as<std::remove_cvref_t<T2>, unique_handle> && concepts::not_same_as<std::remove_cvref_t<T2>, nullhandle_t> && concepts::initializes<std::remove_cvref_t<T2>, T>
constexpr unique_handleoperator= (T2 &&value)
 Assignment operator overload for assigning the value.
 
template<class... TArgs>
requires std::constructible_from<T, TArgs...>
constexpr unique_handle (std::in_place_t, TArgs &&... args)
 Constructor overload for directly initializing the value with a set of arguments.
 
template<class... TArgs>
requires std::constructible_from<T, TArgs...>
constexpr unique_handle (std::in_place_t, const delete_action_type &deleteAction, TArgs &&... args)
 Constructor overload for directly initializing the value with a set of arguments and also initializing the delete action.
 
template<class... TArgs>
requires std::constructible_from<T, TArgs...>
SL_UNIQUE_HANDLE_FULL_CONSTEXPR void emplace (TArgs &&... args)
 Constructor overload for directly initializing the value with a set of arguments.
 
SL_UNIQUE_HANDLE_FULL_CONSTEXPR void reset () noexcept
 Resets the value and invokes the delete action if value was initialized.
 
constexpr const T & raw () const
 Immutable access to the value. No checks will be performed.
 
constexpr const T & operator* () const noexcept
 Immutable access to the value. No checks will be performed.
 
constexpr const T * operator-> () const noexcept
 Immutable access to the value. No checks will be performed.
 
constexpr operator bool () const noexcept
 Checks whether the value is initialized.
 
constexpr bool is_valid () const noexcept
 Checks whether the value is initialized.
 
constexpr const delete_action_typedelete_action () const noexcept
 Immutable access to the delete action.
 
template<std::equality_comparable_with< T > T2, class TOtherDeleteAction >
constexpr bool operator== (const unique_handle< T2, TOtherDeleteAction > &other) const
 Equality-comparison operator overload between two unique_handles. operator != is implicitly defined.
 
template<std::three_way_comparable_with< T > T2, class TOtherDeleteAction >
constexpr std::compare_three_way_result_t< T, T2 > operator<=> (const unique_handle< T2, TOtherDeleteAction > &other) const
 Three-way-comparison operator overload between two unique_handles.
 
template<class T2 >
requires concepts::not_same_as<std::remove_cvref_t<T2>, unique_handle> && std::three_way_comparable_with<T, T2>
constexpr std::compare_three_way_result_t< T, T2 > operator<=> (const T2 &other) const
 Three-way-comparison operator overload for comparison between a unique_handle and a value.
 
template<class T2 >
requires concepts::not_same_as<std::remove_cvref_t<T2>, unique_handle> && std::equality_comparable_with<T, T2>
constexpr bool operator== (const T2 &other) const
 Equality-comparison operator overload for comparison between a unique_handle and a value. operator != is implicitly defined.
 
constexpr bool operator== (nullhandle_t) const noexcept
 Equality-comparison operator overload for comparison of unique_handle and nullhandle_t.
 
constexpr std::strong_ordering operator<=> (nullhandle_t) const noexcept
 Three-way-comparison operator overload for comparison of unique_handle and nullhandle_t.
 

Friends

template<value T2, delete_action_for< T2 > TOtherDeleteAction>
class unique_handle
 

Related Functions

(Note that these are not member functions.)

template<class T , class TDeleteAction >
 unique_handle (T, TDeleteAction) -> unique_handle< detail::type_t< detail::value_validator< T > >, detail::type_t< detail::delete_action_validator< T, TDeleteAction > > >
 Deduction guide for unique_handle class.
 
template<class T >
 unique_handle (T) -> unique_handle< T >
 Deduction guide for unique_handle class.
 

Detailed Description

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
class sl::unique_handle< T, TDeleteAction >

This type models some kind of std::optional behaviour but resets itself on move operations.

For more details and information about related components go to unique_handle group page.

Template Parameters
TThe type of the stored value
TDeleteActionType of the used delete action

Member Typedef Documentation

◆ delete_action_type

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
using sl::unique_handle< T, TDeleteAction >::delete_action_type = TDeleteAction

Type of the used delete action.

◆ value_type

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
using sl::unique_handle< T, TDeleteAction >::value_type = T

Type of the stored value.

Constructor & Destructor Documentation

◆ unique_handle() [1/8]

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
constexpr sl::unique_handle< T, TDeleteAction >::unique_handle ( )
constexprdefaultnoexcept

Default constructor. The value will be in an uninitialized stated and the delete action gets default constructed.

◆ ~unique_handle()

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
constexpr sl::unique_handle< T, TDeleteAction >::~unique_handle ( )
inlineconstexprnoexcept

Destruct. Does invoke the delete action if the value is in an initialized state.

◆ unique_handle() [2/8]

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
SL_UNIQUE_HANDLE_FULL_CONSTEXPR sl::unique_handle< T, TDeleteAction >::unique_handle ( unique_handle< T, TDeleteAction > &&  other)
inlinenoexcept

Move constructor, which relocates the ownership of the value to the target and resets the source. Delete actions will be copied.

Parameters
otherThe source object which will lose ownership, if it has any.

◆ unique_handle() [3/8]

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
sl::unique_handle< T, TDeleteAction >::unique_handle ( const unique_handle< T, TDeleteAction > &  )
delete

Explicitly deleted copy constructor.

◆ unique_handle() [4/8]

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
constexpr sl::unique_handle< T, TDeleteAction >::unique_handle ( nullhandle_t  ,
const delete_action_type deleteAction = delete_action_type() 
)
inlineconstexprnoexcept

Explicitly does not initialize the value. This overload is mainly used for convenience when returning a nullhandle.

Parameters
deleteActionThe provided delete action object

◆ unique_handle() [5/8]

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
constexpr sl::unique_handle< T, TDeleteAction >::unique_handle ( const delete_action_type deleteAction)
inlineconstexprnoexcept

Constructor overload for explicitly providing a delete action.

Parameters
deleteActionThe provided delete action object

◆ unique_handle() [6/8]

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
template<concepts::initializes< T > T2>
requires concepts::not_same_as<std::remove_cvref_t<T2>, unique_handle> && concepts::not_same_as<std::remove_cvref_t<T2>, nullhandle_t>
!std ::convertible_to< T2 &&, T > constexpr sl::unique_handle< T, TDeleteAction >::unique_handle ( T2 &&  value,
const delete_action_type deleteAction = delete_action_type{} 
)
inlineexplicitconstexpr

Constructor overload for initializing the value.

Template Parameters
T2Type of the provided value. Must be convertible to T.
Parameters
valueUsed object to initialize the value
deleteActionThe provided delete action object

◆ unique_handle() [7/8]

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
template<class... TArgs>
requires std::constructible_from<T, TArgs...>
constexpr sl::unique_handle< T, TDeleteAction >::unique_handle ( std::in_place_t  ,
TArgs &&...  args 
)
inlineexplicitconstexpr

Constructor overload for directly initializing the value with a set of arguments.

Template Parameters
TArgsType of the provided arguments.
Parameters
argsUsed arguments to initialize the value

◆ unique_handle() [8/8]

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
template<class... TArgs>
requires std::constructible_from<T, TArgs...>
constexpr sl::unique_handle< T, TDeleteAction >::unique_handle ( std::in_place_t  ,
const delete_action_type deleteAction,
TArgs &&...  args 
)
inlineexplicitconstexpr

Constructor overload for directly initializing the value with a set of arguments and also initializing the delete action.

Template Parameters
TArgsType of the provided arguments.
Parameters
deleteActionThe provided delete action object
argsUsed arguments to initialize the value

Member Function Documentation

◆ delete_action()

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
constexpr const delete_action_type & sl::unique_handle< T, TDeleteAction >::delete_action ( ) const
inlineconstexprnoexcept

Immutable access to the delete action.

Returns
A const reference to the delete action

◆ emplace()

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
template<class... TArgs>
requires std::constructible_from<T, TArgs...>
SL_UNIQUE_HANDLE_FULL_CONSTEXPR void sl::unique_handle< T, TDeleteAction >::emplace ( TArgs &&...  args)
inline

Constructor overload for directly initializing the value with a set of arguments.

Template Parameters
TArgsType of the provided arguments.
Parameters
argsUsed arguments to initialize the value

◆ is_valid()

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
constexpr bool sl::unique_handle< T, TDeleteAction >::is_valid ( ) const
inlineconstexprnoexcept

Checks whether the value is initialized.

Returns
True if value is initialized
Here is the caller graph for this function:

◆ operator bool()

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
constexpr sl::unique_handle< T, TDeleteAction >::operator bool ( ) const
inlineexplicitconstexprnoexcept

Checks whether the value is initialized.

Returns
True if value is initialized

◆ operator*()

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
constexpr const T & sl::unique_handle< T, TDeleteAction >::operator* ( ) const
inlineconstexprnoexcept

Immutable access to the value. No checks will be performed.

Returns
A const reference to the value

◆ operator->()

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
constexpr const T * sl::unique_handle< T, TDeleteAction >::operator-> ( ) const
inlineconstexprnoexcept

Immutable access to the value. No checks will be performed.

Returns
A const pointer to the value

◆ operator<=>() [1/3]

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
template<class T2 >
requires concepts::not_same_as<std::remove_cvref_t<T2>, unique_handle> && std::three_way_comparable_with<T, T2>
constexpr std::compare_three_way_result_t< T, T2 > sl::unique_handle< T, TDeleteAction >::operator<=> ( const T2 &  other) const
inlineconstexpr

Three-way-comparison operator overload for comparison between a unique_handle and a value.

Template Parameters
T2Type of right-hand-side. Must be three-way-comparable to T
Parameters
otherThe object to compare with
Returns
If the handle's value is initialized, both values will be compared. Otherwise handle is less.

◆ operator<=>() [2/3]

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
template<std::three_way_comparable_with< T > T2, class TOtherDeleteAction >
constexpr std::compare_three_way_result_t< T, T2 > sl::unique_handle< T, TDeleteAction >::operator<=> ( const unique_handle< T2, TOtherDeleteAction > &  other) const
inlineconstexpr

Three-way-comparison operator overload between two unique_handles.

Template Parameters
T2Other value type.
TOtherDeleteActionOther delete action type.
Parameters
otherThe object to compare with
Returns
If both handles have initialized values, both values will be compared. Otherwise they will be compared in accordance to the result of is_valid().

◆ operator<=>() [3/3]

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
constexpr std::strong_ordering sl::unique_handle< T, TDeleteAction >::operator<=> ( nullhandle_t  ) const
inlineconstexprnoexcept

Three-way-comparison operator overload for comparison of unique_handle and nullhandle_t.

Returns
Returns std::strong_ordering::equal if handle's value is uninitialized, otherwise std::strong_ordering::greater.
Here is the call graph for this function:

◆ operator=() [1/4]

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
unique_handle & sl::unique_handle< T, TDeleteAction >::operator= ( const unique_handle< T, TDeleteAction > &  )
delete

Explicitly deleted copy assignment.

Returns
nothing

◆ operator=() [2/4]

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
SL_UNIQUE_HANDLE_FULL_CONSTEXPR unique_handle & sl::unique_handle< T, TDeleteAction >::operator= ( nullhandle_t  )
inlinenoexcept

Explicitly resets the value and invokes the delete action if value was initialized.

◆ operator=() [3/4]

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
template<concepts::assignable_to< T & > T2>
requires concepts::not_same_as<std::remove_cvref_t<T2>, unique_handle> && concepts::not_same_as<std::remove_cvref_t<T2>, nullhandle_t> && concepts::initializes<std::remove_cvref_t<T2>, T>
constexpr unique_handle & sl::unique_handle< T, TDeleteAction >::operator= ( T2 &&  value)
inlineconstexpr

Assignment operator overload for assigning the value.

Template Parameters
T2Type of the provided value. Must be convertible to T.
Parameters
valueUsed object to assign the value
Returns
A reference to this

◆ operator=() [4/4]

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
SL_UNIQUE_HANDLE_FULL_CONSTEXPR unique_handle & sl::unique_handle< T, TDeleteAction >::operator= ( unique_handle< T, TDeleteAction > &&  other)
inlinenoexcept

Move assignment, which relocates the ownership of the value to the target and resets the source. Delete actions will be copied.

Parameters
otherThe source object which will lose ownership, if it has any.
Returns
A reference to the target object

◆ operator==() [1/3]

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
template<class T2 >
requires concepts::not_same_as<std::remove_cvref_t<T2>, unique_handle> && std::equality_comparable_with<T, T2>
constexpr bool sl::unique_handle< T, TDeleteAction >::operator== ( const T2 &  other) const
inlineconstexpr

Equality-comparison operator overload for comparison between a unique_handle and a value. operator != is implicitly defined.

Template Parameters
T2Type of right-hand-side. Must be equality-comparable to T
Parameters
otherThe object to compare with
Returns
Returns true if handle is valid and value compares equal equal to rhs. Otherwise false.

◆ operator==() [2/3]

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
template<std::equality_comparable_with< T > T2, class TOtherDeleteAction >
constexpr bool sl::unique_handle< T, TDeleteAction >::operator== ( const unique_handle< T2, TOtherDeleteAction > &  other) const
inlineconstexpr

Equality-comparison operator overload between two unique_handles. operator != is implicitly defined.

Template Parameters
T2Other value type.
TOtherDeleteActionOther delete action type.
Parameters
otherThe unique_handle to compare with
Returns
Both sides compare equal if both handles contain uninitialized values or both value are initialized and compare equal. Otherwise false is returned.

◆ operator==() [3/3]

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
constexpr bool sl::unique_handle< T, TDeleteAction >::operator== ( nullhandle_t  ) const
inlineconstexprnoexcept

Equality-comparison operator overload for comparison of unique_handle and nullhandle_t.

Returns
Returns true if handle's value is uninitialized.
Here is the call graph for this function:

◆ raw()

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
constexpr const T & sl::unique_handle< T, TDeleteAction >::raw ( ) const
inlineconstexpr

Immutable access to the value. No checks will be performed.

Exceptions
Throwsbad_handle_access if value is uninitialized.
Returns
A const reference to the value

◆ reset()

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
SL_UNIQUE_HANDLE_FULL_CONSTEXPR void sl::unique_handle< T, TDeleteAction >::reset ( )
inlinenoexcept

Resets the value and invokes the delete action if value was initialized.

◆ swap()

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
constexpr void sl::unique_handle< T, TDeleteAction >::swap ( unique_handle< T, TDeleteAction > &  other)
inlineconstexprnoexcept

Swaps the target and the source in a more efficient way.

Parameters
otherThe source object
Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ unique_handle

template<value T, delete_action_for< T > TDeleteAction = default_delete_action>
template<value T2, delete_action_for< T2 > TOtherDeleteAction>
friend class unique_handle
friend

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