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

An atomic version of std::unique_ptr. More...

#include <atomic/UniquePointer.hpp>

Public Types

using UnownedPointer = tools::UnownedPointer< Element, Deleter >
 A pointer that is used as the value in cases where ownership is not transferred.
 

Public Member Functions

constexpr UniquePointer () noexcept=default
 Default constructor.
 
 UniquePointer (std::unique_ptr< Element, Deleter > &&value) noexcept
 Constructor that initializes the value from an std::unique_ptr.
 
 UniquePointer (typename std::unique_ptr< Element, Deleter >::pointer object) noexcept
 Constructor that takes ownership of en externally created value.
 
template<typename RelatedElement , typename RelatedDeleter >
requires std::is_constructible_v<std::unique_ptr<Element, Deleter>, std::unique_ptr<RelatedElement, RelatedDeleter> &&>
 UniquePointer (std::unique_ptr< RelatedElement, RelatedDeleter > &&value) noexcept
 Constructor that initializes the value from a related std::unique_ptr.
 
constexpr UniquePointer (std::nullptr_t) noexcept
 Constructor that creates an empty pointer.
 
 ~UniquePointer () noexcept
 Destructor.
 
auto operator= (std::unique_ptr< Element, Deleter > &&value) noexcept -> void
 Atomically transfers an object from an std::unique_ptr using std::memory_order_seq_cst.
 
template<typename RelatedElement , typename RelatedDeleter >
requires std::is_constructible_v<std::unique_ptr<Element, Deleter>, std::unique_ptr<RelatedElement, RelatedDeleter> &&>
auto operator= (std::unique_ptr< RelatedElement, RelatedDeleter > &&value) noexcept -> void
 Atomically transfers an object from a related std::unique_ptr using std::memory_order_seq_cst.
 
auto operator= (std::nullptr_t) noexcept -> void
 Atomically empties the pointer using std::memory_order_seq_cst.
 
 operator UnownedPointer () const &noexcept
 Atomically fetches the stored object using std::memory_order_seq_cst without taking ownership.
 
 operator std::unique_ptr< Element, Deleter > () &&noexcept
 Atomically fetches the stored object using std::memory_order_seq_cst and takes ownership.
 
auto load (std::memory_order memoryOrder=std::memory_order_seq_cst) const noexcept -> UnownedPointer
 Atomically loads the stored pointer.
 
auto store (std::unique_ptr< Element, Deleter > value, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> void
 Atomically transfers an object 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> &&>
auto store (std::unique_ptr< RelatedElement, RelatedDeleter > value, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> void
 Atomically transfers an object from a related std::unique_ptr using std::memory_order_seq_cst.
 
auto store (std::nullptr_t, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> void
 Atomically empties the pointer using std::memory_order_seq_cst.
 
auto exchange (std::unique_ptr< Element, Deleter > &&value, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> std::unique_ptr< Element, Deleter >
 Atomically transfers an object from an std::unique_ptr and returns the previous object.
 
template<typename RelatedElement , typename RelatedDeleter >
requires std::is_constructible_v<std::unique_ptr<Element, Deleter>, std::unique_ptr<RelatedElement, RelatedDeleter> &&>
auto exchange (std::unique_ptr< RelatedElement, RelatedDeleter > &&value, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> std::unique_ptr< Element, Deleter >
 Atomically transfers an object from an std::unique_ptr and returns the previous object.
 
auto exchange (std::nullptr_t, std::memory_order memoryOrder) noexcept -> std::unique_ptr< Element, Deleter >
 Atomically empties the pointer and returns the contained object.
 
auto compare_exchange_weak (UnownedPointer &expectedValue, std::unique_ptr< Element, Deleter > &&newValue, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> bool
 Conditionally atomically exchanges the value with the object contained in an std::unique_ptr.
 
auto compare_exchange_weak (UnownedPointer &expectedValue, std::unique_ptr< Element, Deleter > &&newValue, std::memory_order memoryOrderForSuccess, std::memory_order memoryOrderForFailure) noexcept -> bool
 Conditionally atomically exchanges the value with the object contained in an std::unique_ptr.
 
auto compare_exchange_weak (UnownedPointer &expectedValue, std::unique_ptr< Element, Deleter > &oldValue, std::unique_ptr< Element, Deleter > &&newValue, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> bool
 Conditionally atomically exchanges the value with the object contained in an std::unique_ptr and retreives the previous object.
 
auto compare_exchange_weak (UnownedPointer &expectedValue, std::unique_ptr< Element, Deleter > &oldValue, std::unique_ptr< Element, Deleter > &&newValue, std::memory_order memoryOrderForSuccess, std::memory_order memoryOrderForFailure) noexcept -> bool
 Conditionally atomically exchanges the value with the object contained in an std::unique_ptr and retreives the previous object.
 
template<typename RelatedElement , typename RelatedDeleter >
requires std::is_constructible_v<std::unique_ptr<Element, Deleter>, std::unique_ptr<RelatedElement, RelatedDeleter> &&>
auto compare_exchange_weak (UnownedPointer &expectedValue, std::unique_ptr< RelatedElement, RelatedDeleter > &&newValue, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> bool
 Conditionally atomically exchanges the value with the object contained in a related std::unique_ptr.
 
template<typename RelatedElement , typename RelatedDeleter >
requires std::is_constructible_v<std::unique_ptr<Element, Deleter>, std::unique_ptr<RelatedElement, RelatedDeleter> &&>
auto compare_exchange_weak (UnownedPointer &expectedValue, std::unique_ptr< RelatedElement, RelatedDeleter > &&newValue, std::memory_order memoryOrderForSuccess, std::memory_order memoryOrderForFailure) noexcept -> bool
 Conditionally atomically exchanges the value with the object contained in a related std::unique_ptr.
 
template<typename RelatedElement , typename RelatedDeleter >
requires std::is_constructible_v<std::unique_ptr<Element, Deleter>, std::unique_ptr<RelatedElement, RelatedDeleter> &&>
auto compare_exchange_weak (UnownedPointer &expectedValue, std::unique_ptr< Element, Deleter > &oldValue, std::unique_ptr< RelatedElement, RelatedDeleter > &&newValue, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> bool
 Conditionally atomically exchanges the value with the object contained in a related std::unique_ptr and retreives the previous object.
 
template<typename RelatedElement , typename RelatedDeleter >
requires std::is_constructible_v<std::unique_ptr<Element, Deleter>, std::unique_ptr<RelatedElement, RelatedDeleter> &&>
auto compare_exchange_weak (UnownedPointer &expectedValue, std::unique_ptr< Element, Deleter > &oldValue, std::unique_ptr< RelatedElement, RelatedDeleter > &&newValue, std::memory_order memoryOrderForSuccess, std::memory_order memoryOrderForFailure) noexcept -> bool
 Conditionally atomically exchanges the value with the object contained in a related std::unique_ptr and retreives the previous object.
 
auto compare_exchange_weak (UnownedPointer &expectedValue, std::nullptr_t, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> bool
 Conditionally atomically exchanges the value with with an empty pointer.
 
auto compare_exchange_weak (UnownedPointer &expectedValue, std::nullptr_t, std::memory_order memoryOrderForSuccess, std::memory_order memoryOrderForFailure) noexcept -> bool
 Conditionally atomically exchanges the value with an empty pointer.
 
auto compare_exchange_weak (UnownedPointer &expectedValue, std::unique_ptr< Element, Deleter > &oldValue, std::nullptr_t, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> bool
 Conditionally atomically exchanges the value with with an empty pointer and retreives the previous object.
 
auto compare_exchange_weak (UnownedPointer &expectedValue, std::unique_ptr< Element, Deleter > &oldValue, std::nullptr_t, std::memory_order memoryOrderForSuccess, std::memory_order memoryOrderForFailure) noexcept -> bool
 Conditionally atomically exchanges the value with an empty pointer and retreives the previous object.
 
auto compare_exchange_strong (UnownedPointer &expectedValue, std::unique_ptr< Element, Deleter > &&newValue, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> bool
 Conditionally atomically exchanges the value with the object contained in an std::unique_ptr.
 
auto compare_exchange_strong (UnownedPointer &expectedValue, std::unique_ptr< Element, Deleter > &&newValue, std::memory_order memoryOrderForSuccess, std::memory_order memoryOrderForFailure) noexcept -> bool
 Conditionally atomically exchanges the value with the object contained in an std::unique_ptr.
 
auto compare_exchange_strong (UnownedPointer &expectedValue, std::unique_ptr< Element, Deleter > &oldValue, std::unique_ptr< Element, Deleter > &&newValue, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> bool
 Conditionally atomically exchanges the value with the object contained in an std::unique_ptr and retreives the previous object.
 
auto compare_exchange_strong (UnownedPointer &expectedValue, std::unique_ptr< Element, Deleter > &oldValue, std::unique_ptr< Element, Deleter > &&newValue, std::memory_order memoryOrderForSuccess, std::memory_order memoryOrderForFailure) noexcept -> bool
 Conditionally atomically exchanges the value with the object contained in an std::unique_ptr and retreives the previous object.
 
template<typename RelatedElement , typename RelatedDeleter >
requires std::is_constructible_v<std::unique_ptr<Element, Deleter>, std::unique_ptr<RelatedElement, RelatedDeleter> &&>
auto compare_exchange_strong (UnownedPointer &expectedValue, std::unique_ptr< RelatedElement, RelatedDeleter > &&newValue, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> bool
 Conditionally atomically exchanges the value with the object contained in a related std::unique_ptr.
 
template<typename RelatedElement , typename RelatedDeleter >
requires std::is_constructible_v<std::unique_ptr<Element, Deleter>, std::unique_ptr<RelatedElement, RelatedDeleter> &&>
auto compare_exchange_strong (UnownedPointer &expectedValue, std::unique_ptr< RelatedElement, RelatedDeleter > &&newValue, std::memory_order memoryOrderForSuccess, std::memory_order memoryOrderForFailure) noexcept -> bool
 Conditionally atomically exchanges the value with the object contained in a related std::unique_ptr.
 
template<typename RelatedElement , typename RelatedDeleter >
requires std::is_constructible_v<std::unique_ptr<Element, Deleter>, std::unique_ptr<RelatedElement, RelatedDeleter> &&>
auto compare_exchange_strong (UnownedPointer &expectedValue, std::unique_ptr< Element, Deleter > &oldValue, std::unique_ptr< RelatedElement, RelatedDeleter > &&newValue, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> bool
 Conditionally atomically exchanges the value with the object contained in a related std::unique_ptr and retreives the previous object.
 
template<typename RelatedElement , typename RelatedDeleter >
requires std::is_constructible_v<std::unique_ptr<Element, Deleter>, std::unique_ptr<RelatedElement, RelatedDeleter> &&>
auto compare_exchange_strong (UnownedPointer &expectedValue, std::unique_ptr< Element, Deleter > &oldValue, std::unique_ptr< RelatedElement, RelatedDeleter > &&newValue, std::memory_order memoryOrderForSuccess, std::memory_order memoryOrderForFailure) noexcept -> bool
 Conditionally atomically exchanges the value with the object contained in a related std::unique_ptr and retreives the previous object.
 
auto compare_exchange_strong (UnownedPointer &expectedValue, std::nullptr_t, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> bool
 Conditionally atomically exchanges the value with with an empty pointer.
 
auto compare_exchange_strong (UnownedPointer &expectedValue, std::nullptr_t, std::memory_order memoryOrderForSuccess, std::memory_order memoryOrderForFailure) noexcept -> bool
 Conditionally atomically exchanges the value with an empty pointer.
 
auto compare_exchange_strong (UnownedPointer &expectedValue, std::unique_ptr< Element, Deleter > &oldValue, std::nullptr_t, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> bool
 Conditionally atomically exchanges the value with with an empty pointer and retreives the previous object.
 
auto compare_exchange_strong (UnownedPointer &expectedValue, std::unique_ptr< Element, Deleter > &oldValue, std::nullptr_t, std::memory_order memoryOrderForSuccess, std::memory_order memoryOrderForFailure) noexcept -> bool
 Conditionally atomically exchanges the value with an empty pointer and retreives the previous object.
 
auto is_lock_free () const noexcept -> bool
 Determines whether operations on this object are lock free.
 
 UniquePointer (const UniquePointer &)=delete
 Deleted copy constructor.
 
auto operator= (const UniquePointer &)=delete
 Deleted assignment opertaor.
 

Static Public Attributes

static constexpr bool is_always_lock_free
 Determines whether operations on all objects of thsi class are lock free.
 

Related Symbols

(Note that these are not member symbols.)

template<typename LhsElement , typename LhsDeleter , typename RhsElement , typename RhsDeleter >
constexpr auto operator== (const UniquePointer< LhsElement, LhsDeleter > &lhs, const UniquePointer< RhsElement, RhsDeleter > &rhs) -> bool
 Comparison between two atomic unique pointers.
 
template<typename LhsElement , typename LhsDeleter , typename RhsElement , typename RhsDeleter >
constexpr auto operator== (const UniquePointer< LhsElement, LhsDeleter > &lhs, const tools::UnownedPointer< RhsElement, RhsDeleter > &rhs) -> bool
 Comparison between an atomic unique pointer and an unowned pointer.
 
template<typename LhsElement , typename LhsDeleter , typename RhsElement , typename RhsDeleter >
constexpr auto operator== (const UniquePointer< LhsElement, LhsDeleter > &lhs, const std::unique_ptr< RhsElement, RhsDeleter > &rhs) -> bool
 Comparison between an atomic unique pointer and an std::unique_ptr.
 
template<typename Element , typename Deleter >
constexpr auto operator== (const UniquePointer< Element, Deleter > &lhs, std::nullptr_t) -> bool
 Comparison between an atomic unique pointer and a null pointer.
 
template<typename LhsElement , typename LhsDeleter , typename RhsElement , typename RhsDeleter >
constexpr auto operator (const UniquePointer< LhsElement, LhsDeleter > &lhs, const UniquePointer< RhsElement, RhsDeleter > &rhs) -> auto
 Tree-way comparison between two unowned pointers.
 
template<typename LhsElement , typename LhsDeleter , typename RhsElement , typename RhsDeleter >
constexpr auto operator (const UniquePointer< LhsElement, LhsDeleter > &lhs, const tools::UnownedPointer< RhsElement, RhsDeleter > &rhs) -> auto
 Tree-way comparison between an atomic unique pointer and an unowned pointer.
 
template<typename LhsElement , typename LhsDeleter , typename RhsElement , typename RhsDeleter >
constexpr auto operator (const UniquePointer< LhsElement, LhsDeleter > &lhs, const std::unique_ptr< RhsElement, RhsDeleter > &rhs) -> auto
 Tree-way comparison between an atomic unique pointer and an std::unique_ptr.
 
template<typename Element , typename Deleter >
constexpr auto operator (const UniquePointer< Element, Deleter > &lhs, std::nullptr_t) -> auto
 Tree-way comparison between an atomic unique pointer and a null pointer.
 

Detailed Description

template<typename Element, typename Deleter = std::default_delete<Element>>
class xentara::utils::atomic::UniquePointer< Element, Deleter >

An atomic version of std::unique_ptr.

Template Parameters
ElementThe type of object the pointer controls
Deleter

The deleter to use to delete objects. This must be an empty type.

The deleter must be stateless, meaning that one deleter can be replacable by any other default constructed deleter. This is necessary because the deleter cannot be stored atomically, so it will be destroyed when a value is stored, and a new deleter will be created when the value is retreived.

In addition, if Deleter has a member type named pointer, that type must be suitable for use with std::atomic.

Member Typedef Documentation

◆ UnownedPointer

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

A pointer that is used as the value in cases where ownership is not transferred.

Constructor & Destructor Documentation

◆ UniquePointer() [1/6]

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

Default constructor.

This constructor creates an empty pointer that does not hold an object.

◆ UniquePointer() [2/6]

template<typename Element , typename Deleter = std::default_delete<Element>>
xentara::utils::atomic::UniquePointer< Element, Deleter >::UniquePointer ( std::unique_ptr< Element, Deleter > &&  value)
noexcept

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

Parameters
valueThe pointer to initialize from. Any object the pointer holds will be transferred to the atomic.

◆ UniquePointer() [3/6]

template<typename Element , typename Deleter = std::default_delete<Element>>
xentara::utils::atomic::UniquePointer< Element, Deleter >::UniquePointer ( typename std::unique_ptr< Element, Deleter >::pointer  object)
explicitnoexcept

Constructor that takes ownership of en externally created value.

Parameters
objectThe object, or nullpt to create an empty value. The atomic will take ownership of the object.

◆ UniquePointer() [4/6]

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> &&>
xentara::utils::atomic::UniquePointer< Element, Deleter >::UniquePointer ( std::unique_ptr< RelatedElement, RelatedDeleter > &&  value)
noexcept

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

Parameters
valueThe pointer to initialize from. Any object the pointer holds will be transferred to the atomic.

◆ UniquePointer() [5/6]

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

Constructor that creates an empty pointer.

This constructor creates a pointer that does not contain an object. It is equivalient to the default constructor.

◆ ~UniquePointer()

template<typename Element , typename Deleter = std::default_delete<Element>>
xentara::utils::atomic::UniquePointer< Element, Deleter >::~UniquePointer ( )
noexcept

Destructor.

This destructor deletes any object the atomic may be holding.

◆ UniquePointer() [6/6]

template<typename Element , typename Deleter = std::default_delete<Element>>
xentara::utils::atomic::UniquePointer< Element, Deleter >::UniquePointer ( const UniquePointer< Element, Deleter > &  )
delete

Deleted copy constructor.

Member Function Documentation

◆ compare_exchange_strong() [1/12]

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::compare_exchange_strong ( UnownedPointer expectedValue,
std::nullptr_t  ,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> bool
noexcept

Conditionally atomically exchanges the value with with an empty pointer.

If the comparison succeeds and the values are exchanged, the previous object (if any) is destroyed.

Attention
If the comparison succeeds, the old object is deleted, but expectedValue will still contain a pointer to it. This means that, if the function return true, expectedValue will point to a deleted object and must not be dereferenced.
Parameters
expectedValueThe expected value. The atomic will only be emptied if it currently contains this value. If the comparison fails, expectedValue will be set to the actual value of the atomic.
memoryOrderThe memory order used to exchange the value.
Returns
If the comparison succeeds, true is returned, together with an std::unique_ptr holding the previous object, if any. If the comparison fails, false is returned, together with an empty std::unique_ptr.
See also
std::atomic::compare_exchange_strong()

◆ compare_exchange_strong() [2/12]

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::compare_exchange_strong ( UnownedPointer expectedValue,
std::nullptr_t  ,
std::memory_order  memoryOrderForSuccess,
std::memory_order  memoryOrderForFailure 
) -> bool
noexcept

Conditionally atomically exchanges the value with an empty pointer.

If the comparison succeeds and the values are exchanged, the previous object (if any) is destroyed.

Attention
If the comparison succeeds, the old object is deleted, but expectedValue will still contain a pointer to it. This means that, if the function return true, expectedValue will point to a deleted object and must not be dereferenced.
Parameters
expectedValueThe expected value. The atomic will only be emptied if it currently contains this value. If the comparison fails, expectedValue will be set to the actual value of the atomic.
memoryOrderForSuccessThe memory order used if the comparison succeeds.
memoryOrderForFailureThe memory order used if the comparison fails.
Returns
If the comparison succeeds, true is returned, together with an std::unique_ptr holding the previous object, if any. If the comparison fails, false is returned, together with an empty std::unique_ptr.
See also
std::atomic::compare_exchange_strong()

◆ compare_exchange_strong() [3/12]

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::compare_exchange_strong ( UnownedPointer expectedValue,
std::unique_ptr< Element, Deleter > &&  newValue,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> bool
noexcept

Conditionally atomically exchanges the value with the object contained in an std::unique_ptr.

If the comparison succeeds and the values are exchanged, the previous object (if any) is destroyed.

Attention
If the comparison succeeds, the old object is deleted, but expectedValue will still contain a pointer to it. This means that, if the function return true, expectedValue will point to a deleted object and must not be dereferenced.
Parameters
expectedValueThe expected value. The new value will only be set if the atomic currently contains this value. If the comparison fails, expectedValue will be set to the actual value of the atomic.
newValueThe pointer to transfer the object from if the comparison is successful. Any object the pointer holds will then be transferred to the atomic. If the comparison fails, newValue will retain the object, so the function can be called again.
memoryOrderThe memory order used to exchange the value.
Returns
Returns true if the values were exchanged, or false if the comparison failed.
See also
std::atomic::compare_exchange_strong()

◆ compare_exchange_strong() [4/12]

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::compare_exchange_strong ( UnownedPointer expectedValue,
std::unique_ptr< Element, Deleter > &&  newValue,
std::memory_order  memoryOrderForSuccess,
std::memory_order  memoryOrderForFailure 
) -> bool
noexcept

Conditionally atomically exchanges the value with the object contained in an std::unique_ptr.

If the comparison succeeds and the values are exchanged, the previous object (if any) is destroyed.

Attention
If the comparison succeeds, the old object is deleted, but expectedValue will still contain a pointer to it. This means that, if the function return true, expectedValue will point to a deleted object and must not be dereferenced.
Parameters
expectedValueThe expected value. The new value will only be set if the atomic currently contains this value. If the comparison fails, expectedValue will be set to the actual value of the atomic.
newValueThe pointer to transfer the object from if the comparison is successful. Any object the pointer holds will then be transferred to the atomic. If the comparison fails, newValue will retain the object, so the function can be called again.
memoryOrderForSuccessThe memory order used if the comparison succeeds.
memoryOrderForFailureThe memory order used if the comparison fails.
Returns
If the comparison succeeds, true is returned, together with an std::unique_ptr holding the previous object, if any. If the comparison fails, false is returned, together with an empty std::unique_ptr.
See also
std::atomic::compare_exchange_strong()

◆ compare_exchange_strong() [5/12]

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::compare_exchange_strong ( UnownedPointer expectedValue,
std::unique_ptr< Element, Deleter > &  oldValue,
std::nullptr_t  ,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> bool
noexcept

Conditionally atomically exchanges the value with with an empty pointer and retreives the previous object.

Parameters
expectedValueThe expected value. The atomic will only be emptied if it currently contains this value. If the comparison fails, expectedValue will be set to the actual value of the atomic.
oldValueIf the comparison succeeds and the values are exchanged, ownership of the previous object (if any) is transferred to this pointer.
memoryOrderThe memory order used to exchange the value.
Returns
If the comparison succeeds, true is returned, together with an std::unique_ptr holding the previous object, if any. If the comparison fails, false is returned, together with an empty std::unique_ptr.
See also
std::atomic::compare_exchange_strong()

◆ compare_exchange_strong() [6/12]

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::compare_exchange_strong ( UnownedPointer expectedValue,
std::unique_ptr< Element, Deleter > &  oldValue,
std::nullptr_t  ,
std::memory_order  memoryOrderForSuccess,
std::memory_order  memoryOrderForFailure 
) -> bool
noexcept

Conditionally atomically exchanges the value with an empty pointer and retreives the previous object.

Parameters
expectedValueThe expected value. The atomic will only be emptied if it currently contains this value. If the comparison fails, expectedValue will be set to the actual value of the atomic.
oldValueIf the comparison succeeds and the values are exchanged, ownership of the previous object (if any) is transferred to this pointer.
memoryOrderForSuccessThe memory order used if the comparison succeeds.
memoryOrderForFailureThe memory order used if the comparison fails.
Returns
If the comparison succeeds, true is returned, together with an std::unique_ptr holding the previous object, if any. If the comparison fails, false is returned, together with an empty std::unique_ptr.
See also
std::atomic::compare_exchange_strong()

◆ compare_exchange_strong() [7/12]

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::compare_exchange_strong ( UnownedPointer expectedValue,
std::unique_ptr< Element, Deleter > &  oldValue,
std::unique_ptr< Element, Deleter > &&  newValue,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> bool
noexcept

Conditionally atomically exchanges the value with the object contained in an std::unique_ptr and retreives the previous object.

Parameters
expectedValueThe expected value. The new value will only be set if the atomic currently contains this value. If the comparison fails, expectedValue will be set to the actual value of the atomic.
oldValueIf the comparison succeeds and the values are exchanged, ownership of the previous object (if any) is transferred to this pointer.
newValueThe pointer to transfer the object from if the comparison is successful. Any object the pointer holds will then be transferred to the atomic. If the comparison fails, newValue will retain the object, so the function can be called again.
memoryOrderThe memory order used to exchange the value.
Returns
If the comparison succeeds, true is returned, together with an std::unique_ptr holding the previous object, if any. If the comparison fails, false is returned, together with an empty std::unique_ptr.
See also
std::atomic::compare_exchange_strong()

◆ compare_exchange_strong() [8/12]

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::compare_exchange_strong ( UnownedPointer expectedValue,
std::unique_ptr< Element, Deleter > &  oldValue,
std::unique_ptr< Element, Deleter > &&  newValue,
std::memory_order  memoryOrderForSuccess,
std::memory_order  memoryOrderForFailure 
) -> bool
noexcept

Conditionally atomically exchanges the value with the object contained in an std::unique_ptr and retreives the previous object.

Parameters
expectedValueThe expected value. The new value will only be set if the atomic currently contains this value. If the comparison fails, expectedValue will be set to the actual value of the atomic.
oldValueIf the comparison succeeds and the values are exchanged, ownership of the previous object (if any) is transferred to this pointer.
newValueThe pointer to transfer the object from if the comparison is successful. Any object the pointer holds will then be transferred to the atomic. If the comparison fails, newValue will retain the object, so the function can be called again.
memoryOrderForSuccessThe memory order used if the comparison succeeds.
memoryOrderForFailureThe memory order used if the comparison fails.
Returns
If the comparison succeeds, true is returned, together with an std::unique_ptr holding the previous object, if any. If the comparison fails, false is returned, together with an empty std::unique_ptr.
See also
std::atomic::compare_exchange_strong()

◆ compare_exchange_strong() [9/12]

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> &&>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::compare_exchange_strong ( UnownedPointer expectedValue,
std::unique_ptr< Element, Deleter > &  oldValue,
std::unique_ptr< RelatedElement, RelatedDeleter > &&  newValue,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> bool
noexcept

Conditionally atomically exchanges the value with the object contained in a related std::unique_ptr and retreives the previous object.

Parameters
expectedValueThe expected value. The new value will only be set if the atomic currently contains this value. If the comparison fails, expectedValue will be set to the actual value of the atomic.
oldValueIf the comparison succeeds and the values are exchanged, ownership of the previous object (if any) is transferred to this pointer.
newValueThe pointer to transfer the object from if the comparison is successful. Any object the pointer holds will then be transferred to the atomic. If the comparison fails, newValue will retain the object, so the function can be called again.
memoryOrderThe memory order used to exchange the value.
Returns
If the comparison succeeds, true is returned, together with an std::unique_ptr holding the previous object, if any. If the comparison fails, false is returned, together with an empty std::unique_ptr.
See also
std::atomic::compare_exchange_strong()

◆ compare_exchange_strong() [10/12]

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> &&>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::compare_exchange_strong ( UnownedPointer expectedValue,
std::unique_ptr< Element, Deleter > &  oldValue,
std::unique_ptr< RelatedElement, RelatedDeleter > &&  newValue,
std::memory_order  memoryOrderForSuccess,
std::memory_order  memoryOrderForFailure 
) -> bool
noexcept

Conditionally atomically exchanges the value with the object contained in a related std::unique_ptr and retreives the previous object.

Parameters
expectedValueThe expected value. The new value will only be set if the atomic currently contains this value. If the comparison fails, expectedValue will be set to the actual value of the atomic.
oldValueIf the comparison succeeds and the values are exchanged, ownership of the previous object (if any) is transferred to this pointer.
newValueThe pointer to transfer the object from if the comparison is successful. Any object the pointer holds will then be transferred to the atomic. If the comparison fails, newValue will retain the object, so the function can be called again.
memoryOrderForSuccessThe memory order used if the comparison succeeds.
memoryOrderForFailureThe memory order used if the comparison fails.
Returns
If the comparison succeeds, true is returned, together with an std::unique_ptr holding the previous object, if any. If the comparison fails, false is returned, together with an empty std::unique_ptr.
See also
std::atomic::compare_exchange_strong()

◆ compare_exchange_strong() [11/12]

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> &&>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::compare_exchange_strong ( UnownedPointer expectedValue,
std::unique_ptr< RelatedElement, RelatedDeleter > &&  newValue,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> bool
noexcept

Conditionally atomically exchanges the value with the object contained in a related std::unique_ptr.

If the comparison succeeds and the values are exchanged, the previous object (if any) is destroyed.

Attention
If the comparison succeeds, the old object is deleted, but expectedValue will still contain a pointer to it. This means that, if the function return true, expectedValue will point to a deleted object and must not be dereferenced.
Parameters
expectedValueThe expected value. The new value will only be set if the atomic currently contains this value. If the comparison fails, expectedValue will be set to the actual value of the atomic.
newValueThe pointer to transfer the object from if the comparison is successful. Any object the pointer holds will then be transferred to the atomic. If the comparison fails, newValue will retain the object, so the function can be called again.
memoryOrderThe memory order used to exchange the value.
Returns
If the comparison succeeds, true is returned, together with an std::unique_ptr holding the previous object, if any. If the comparison fails, false is returned, together with an empty std::unique_ptr.
See also
std::atomic::compare_exchange_strong()

◆ compare_exchange_strong() [12/12]

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> &&>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::compare_exchange_strong ( UnownedPointer expectedValue,
std::unique_ptr< RelatedElement, RelatedDeleter > &&  newValue,
std::memory_order  memoryOrderForSuccess,
std::memory_order  memoryOrderForFailure 
) -> bool
noexcept

Conditionally atomically exchanges the value with the object contained in a related std::unique_ptr.

If the comparison succeeds and the values are exchanged, the previous object (if any) is destroyed.

Attention
If the comparison succeeds, the old object is deleted, but expectedValue will still contain a pointer to it. This means that, if the function return true, expectedValue will point to a deleted object and must not be dereferenced.
Parameters
expectedValueThe expected value. The new value will only be set if the atomic currently contains this value. If the comparison fails, expectedValue will be set to the actual value of the atomic.
newValueThe pointer to transfer the object from if the comparison is successful. Any object the pointer holds will then be transferred to the atomic. If the comparison fails, newValue will retain the object, so the function can be called again.
memoryOrderForSuccessThe memory order used if the comparison succeeds.
memoryOrderForFailureThe memory order used if the comparison fails.
Returns
If the comparison succeeds, true is returned, together with an std::unique_ptr holding the previous object, if any. If the comparison fails, false is returned, together with an empty std::unique_ptr.
See also
std::atomic::compare_exchange_strong()

◆ compare_exchange_weak() [1/12]

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::compare_exchange_weak ( UnownedPointer expectedValue,
std::nullptr_t  ,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> bool
noexcept

Conditionally atomically exchanges the value with with an empty pointer.

If the comparison succeeds and the values are exchanged, the previous object (if any) is destroyed.

Attention
If the comparison succeeds, the old object is deleted, but expectedValue will still contain a pointer to it. This means that, if the function return true, expectedValue will point to a deleted object and must not be dereferenced.
Parameters
expectedValueThe expected value. The atomic will only be emptied if it currently contains this value. If the comparison fails, expectedValue will be set to the actual value of the atomic.
memoryOrderThe memory order used to exchange the value.
Returns
If the comparison succeeds, true is returned, together with an std::unique_ptr holding the previous object, if any. If the comparison fails, false is returned, together with an empty std::unique_ptr.
See also
std::atomic::compare_exchange_weak()

◆ compare_exchange_weak() [2/12]

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::compare_exchange_weak ( UnownedPointer expectedValue,
std::nullptr_t  ,
std::memory_order  memoryOrderForSuccess,
std::memory_order  memoryOrderForFailure 
) -> bool
noexcept

Conditionally atomically exchanges the value with an empty pointer.

If the comparison succeeds and the values are exchanged, the previous object (if any) is destroyed.

Attention
If the comparison succeeds, the old object is deleted, but expectedValue will still contain a pointer to it. This means that, if the function return true, expectedValue will point to a deleted object and must not be dereferenced.
Parameters
expectedValueThe expected value. The atomic will only be emptied if it currently contains this value. If the comparison fails, expectedValue will be set to the actual value of the atomic.
memoryOrderForSuccessThe memory order used if the comparison succeeds.
memoryOrderForFailureThe memory order used if the comparison fails.
Returns
If the comparison succeeds, true is returned, together with an std::unique_ptr holding the previous object, if any. If the comparison fails, false is returned, together with an empty std::unique_ptr.
See also
std::atomic::compare_exchange_weak()

◆ compare_exchange_weak() [3/12]

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::compare_exchange_weak ( UnownedPointer expectedValue,
std::unique_ptr< Element, Deleter > &&  newValue,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> bool
noexcept

Conditionally atomically exchanges the value with the object contained in an std::unique_ptr.

If the comparison succeeds and the values are exchanged, the previous object (if any) is destroyed.

Attention
If the comparison succeeds, the old object is deleted, but expectedValue will still contain a pointer to it. This means that, if the function return true, expectedValue will point to a deleted object and must not be dereferenced.
Parameters
expectedValueThe expected value. The new value will only be set if the atomic currently contains this value. If the comparison fails, expectedValue will be set to the actual value of the atomic.
newValueThe pointer to transfer the object from if the comparison is successful. Any object the pointer holds will then be transferred to the atomic. If the comparison fails, newValue will retain the object, so the function can be called again.
memoryOrderThe memory order used to exchange the value.
Returns
Returns true if the values were exchanged, or false if the comparison failed.
See also
std::atomic::compare_exchange_weak()

◆ compare_exchange_weak() [4/12]

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::compare_exchange_weak ( UnownedPointer expectedValue,
std::unique_ptr< Element, Deleter > &&  newValue,
std::memory_order  memoryOrderForSuccess,
std::memory_order  memoryOrderForFailure 
) -> bool
noexcept

Conditionally atomically exchanges the value with the object contained in an std::unique_ptr.

If the comparison succeeds and the values are exchanged, the previous object (if any) is destroyed.

Attention
If the comparison succeeds, the old object is deleted, but expectedValue will still contain a pointer to it. This means that, if the function return true, expectedValue will point to a deleted object and must not be dereferenced.
Parameters
expectedValueThe expected value. The new value will only be set if the atomic currently contains this value. If the comparison fails, expectedValue will be set to the actual value of the atomic.
newValueThe pointer to transfer the object from if the comparison is successful. Any object the pointer holds will then be transferred to the atomic. If the comparison fails, newValue will retain the object, so the function can be called again.
memoryOrderForSuccessThe memory order used if the comparison succeeds.
memoryOrderForFailureThe memory order used if the comparison fails.
Returns
If the comparison succeeds, true is returned, together with an std::unique_ptr holding the previous object, if any. If the comparison fails, false is returned, together with an empty std::unique_ptr.
See also
std::atomic::compare_exchange_weak()

◆ compare_exchange_weak() [5/12]

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::compare_exchange_weak ( UnownedPointer expectedValue,
std::unique_ptr< Element, Deleter > &  oldValue,
std::nullptr_t  ,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> bool
noexcept

Conditionally atomically exchanges the value with with an empty pointer and retreives the previous object.

Parameters
expectedValueThe expected value. The atomic will only be emptied if it currently contains this value. If the comparison fails, expectedValue will be set to the actual value of the atomic.
oldValueIf the comparison succeeds and the values are exchanged, ownership of the previous object (if any) is transferred to this pointer.
memoryOrderThe memory order used to exchange the value.
Returns
If the comparison succeeds, true is returned, together with an std::unique_ptr holding the previous object, if any. If the comparison fails, false is returned, together with an empty std::unique_ptr.
See also
std::atomic::compare_exchange_weak()

◆ compare_exchange_weak() [6/12]

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::compare_exchange_weak ( UnownedPointer expectedValue,
std::unique_ptr< Element, Deleter > &  oldValue,
std::nullptr_t  ,
std::memory_order  memoryOrderForSuccess,
std::memory_order  memoryOrderForFailure 
) -> bool
noexcept

Conditionally atomically exchanges the value with an empty pointer and retreives the previous object.

Parameters
expectedValueThe expected value. The atomic will only be emptied if it currently contains this value. If the comparison fails, expectedValue will be set to the actual value of the atomic.
oldValueIf the comparison succeeds and the values are exchanged, ownership of the previous object (if any) is transferred to this pointer.
memoryOrderForSuccessThe memory order used if the comparison succeeds.
memoryOrderForFailureThe memory order used if the comparison fails.
Returns
If the comparison succeeds, true is returned, together with an std::unique_ptr holding the previous object, if any. If the comparison fails, false is returned, together with an empty std::unique_ptr.
See also
std::atomic::compare_exchange_weak()

◆ compare_exchange_weak() [7/12]

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::compare_exchange_weak ( UnownedPointer expectedValue,
std::unique_ptr< Element, Deleter > &  oldValue,
std::unique_ptr< Element, Deleter > &&  newValue,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> bool
noexcept

Conditionally atomically exchanges the value with the object contained in an std::unique_ptr and retreives the previous object.

Parameters
expectedValueThe expected value. The new value will only be set if the atomic currently contains this value. If the comparison fails, expectedValue will be set to the actual value of the atomic.
oldValueIf the comparison succeeds and the values are exchanged, ownership of the previous object (if any) is transferred to this pointer.
newValueThe pointer to transfer the object from if the comparison is successful. Any object the pointer holds will then be transferred to the atomic. If the comparison fails, newValue will retain the object, so the function can be called again.
memoryOrderThe memory order used to exchange the value.
Returns
If the comparison succeeds, true is returned, together with an std::unique_ptr holding the previous object, if any. If the comparison fails, false is returned, together with an empty std::unique_ptr.
See also
std::atomic::compare_exchange_weak()

◆ compare_exchange_weak() [8/12]

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::compare_exchange_weak ( UnownedPointer expectedValue,
std::unique_ptr< Element, Deleter > &  oldValue,
std::unique_ptr< Element, Deleter > &&  newValue,
std::memory_order  memoryOrderForSuccess,
std::memory_order  memoryOrderForFailure 
) -> bool
noexcept

Conditionally atomically exchanges the value with the object contained in an std::unique_ptr and retreives the previous object.

Parameters
expectedValueThe expected value. The new value will only be set if the atomic currently contains this value. If the comparison fails, expectedValue will be set to the actual value of the atomic.
oldValueIf the comparison succeeds and the values are exchanged, ownership of the previous object (if any) is transferred to this pointer.
newValueThe pointer to transfer the object from if the comparison is successful. Any object the pointer holds will then be transferred to the atomic. If the comparison fails, newValue will retain the object, so the function can be called again.
memoryOrderForSuccessThe memory order used if the comparison succeeds.
memoryOrderForFailureThe memory order used if the comparison fails.
Returns
If the comparison succeeds, true is returned, together with an std::unique_ptr holding the previous object, if any. If the comparison fails, false is returned, together with an empty std::unique_ptr.
See also
std::atomic::compare_exchange_weak()

◆ compare_exchange_weak() [9/12]

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> &&>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::compare_exchange_weak ( UnownedPointer expectedValue,
std::unique_ptr< Element, Deleter > &  oldValue,
std::unique_ptr< RelatedElement, RelatedDeleter > &&  newValue,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> bool
noexcept

Conditionally atomically exchanges the value with the object contained in a related std::unique_ptr and retreives the previous object.

Parameters
expectedValueThe expected value. The new value will only be set if the atomic currently contains this value. If the comparison fails, expectedValue will be set to the actual value of the atomic.
oldValueIf the comparison succeeds and the values are exchanged, ownership of the previous object (if any) is transferred to this pointer.
newValueThe pointer to transfer the object from if the comparison is successful. Any object the pointer holds will then be transferred to the atomic. If the comparison fails, newValue will retain the object, so the function can be called again.
memoryOrderThe memory order used to exchange the value.
Returns
If the comparison succeeds, true is returned, together with an std::unique_ptr holding the previous object, if any. If the comparison fails, false is returned, together with an empty std::unique_ptr.
See also
std::atomic::compare_exchange_weak()

◆ compare_exchange_weak() [10/12]

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> &&>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::compare_exchange_weak ( UnownedPointer expectedValue,
std::unique_ptr< Element, Deleter > &  oldValue,
std::unique_ptr< RelatedElement, RelatedDeleter > &&  newValue,
std::memory_order  memoryOrderForSuccess,
std::memory_order  memoryOrderForFailure 
) -> bool
noexcept

Conditionally atomically exchanges the value with the object contained in a related std::unique_ptr and retreives the previous object.

Parameters
expectedValueThe expected value. The new value will only be set if the atomic currently contains this value. If the comparison fails, expectedValue will be set to the actual value of the atomic.
oldValueIf the comparison succeeds and the values are exchanged, ownership of the previous object (if any) is transferred to this pointer.
newValueThe pointer to transfer the object from if the comparison is successful. Any object the pointer holds will then be transferred to the atomic. If the comparison fails, newValue will retain the object, so the function can be called again.
memoryOrderForSuccessThe memory order used if the comparison succeeds.
memoryOrderForFailureThe memory order used if the comparison fails.
Returns
If the comparison succeeds, true is returned, together with an std::unique_ptr holding the previous object, if any. If the comparison fails, false is returned, together with an empty std::unique_ptr.
See also
std::atomic::compare_exchange_weak()

◆ compare_exchange_weak() [11/12]

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> &&>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::compare_exchange_weak ( UnownedPointer expectedValue,
std::unique_ptr< RelatedElement, RelatedDeleter > &&  newValue,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> bool
noexcept

Conditionally atomically exchanges the value with the object contained in a related std::unique_ptr.

If the comparison succeeds and the values are exchanged, the previous object (if any) is destroyed.

Attention
If the comparison succeeds, the old object is deleted, but expectedValue will still contain a pointer to it. This means that, if the function return true, expectedValue will point to a deleted object and must not be dereferenced.
Parameters
expectedValueThe expected value. The new value will only be set if the atomic currently contains this value. If the comparison fails, expectedValue will be set to the actual value of the atomic.
newValueThe pointer to transfer the object from if the comparison is successful. Any object the pointer holds will then be transferred to the atomic. If the comparison fails, newValue will retain the object, so the function can be called again.
memoryOrderThe memory order used to exchange the value.
Returns
If the comparison succeeds, true is returned, together with an std::unique_ptr holding the previous object, if any. If the comparison fails, false is returned, together with an empty std::unique_ptr.
See also
std::atomic::compare_exchange_weak()

◆ compare_exchange_weak() [12/12]

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> &&>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::compare_exchange_weak ( UnownedPointer expectedValue,
std::unique_ptr< RelatedElement, RelatedDeleter > &&  newValue,
std::memory_order  memoryOrderForSuccess,
std::memory_order  memoryOrderForFailure 
) -> bool
noexcept

Conditionally atomically exchanges the value with the object contained in a related std::unique_ptr.

If the comparison succeeds and the values are exchanged, the previous object (if any) is destroyed.

Attention
If the comparison succeeds, the old object is deleted, but expectedValue will still contain a pointer to it. This means that, if the function return true, expectedValue will point to a deleted object and must not be dereferenced.
Parameters
expectedValueThe expected value. The new value will only be set if the atomic currently contains this value. If the comparison fails, expectedValue will be set to the actual value of the atomic.
newValueThe pointer to transfer the object from if the comparison is successful. Any object the pointer holds will then be transferred to the atomic. If the comparison fails, newValue will retain the object, so the function can be called again.
memoryOrderForSuccessThe memory order used if the comparison succeeds.
memoryOrderForFailureThe memory order used if the comparison fails.
Returns
If the comparison succeeds, true is returned, together with an std::unique_ptr holding the previous object, if any. If the comparison fails, false is returned, together with an empty std::unique_ptr.
See also
std::atomic::compare_exchange_weak()

◆ exchange() [1/3]

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::exchange ( std::nullptr_t  ,
std::memory_order  memoryOrder 
) -> std::unique_ptr<Element, Deleter>
noexcept

Atomically empties the pointer and returns the contained object.

Parameters
memoryOrderThe memory order to use
Returns
A pointer holding the previous object, if any.
See also
std::atomic::exchange()

◆ exchange() [2/3]

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::exchange ( std::unique_ptr< Element, Deleter > &&  value,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> std::unique_ptr<Element, Deleter>
noexcept

Atomically transfers an object from an std::unique_ptr and returns the previous object.

Parameters
valueThe pointer to transfer the object from. Any object the pointer holds will be transferred to the atomic.
memoryOrderThe memory order to use
Returns
A pointer holding the previous object, if any.
See also
std::atomic::exchange()

◆ exchange() [3/3]

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> &&>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::exchange ( std::unique_ptr< RelatedElement, RelatedDeleter > &&  value,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> std::unique_ptr<Element, Deleter>
noexcept

Atomically transfers an object from an std::unique_ptr and returns the previous object.

Parameters
valueThe pointer to transfer the object from. Any object the pointer holds will be transferred to the atomic.
memoryOrderThe memory order to use
Returns
A pointer holding the previous object, if any.
See also
std::atomic::exchange()

◆ is_lock_free()

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::is_lock_free ( ) const -> bool
noexcept

Determines whether operations on this object are lock free.

See also
std::atomic::is_lock_free()

◆ load()

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::load ( std::memory_order  memoryOrder = std::memory_order_seq_cst) const -> UnownedPointer
noexcept

Atomically loads the stored pointer.

Attention
The returned pointer must not be dereferenced, as the object it points to may be deleted at any time by another thread. The pointer must only be used to compare it to other pointers, or to check whether it is null.
Note
This function only inspects the stored pointer, and does not take ownership of the value. To take ownership, you must exchange the value with nullptr using exchange().
See also
std::atomic::load()

◆ operator std::unique_ptr< Element, Deleter >()

template<typename Element , typename Deleter = std::default_delete<Element>>
xentara::utils::atomic::UniquePointer< Element, Deleter >::operator std::unique_ptr< Element, Deleter > ( ) &&
noexcept

Atomically fetches the stored object using std::memory_order_seq_cst and takes ownership.

The object will be removed from the atomic, and ownership will be transferred to the returned std::unique_ptr, leaving the atomic empty. For this reason, this operator can only be called on rvalue references. This means that you must use std::move to retreive the value.

Example:

std::unique_ptr<std::string> value = std::move(atomicPointer);
An atomic version of std::unique_ptr.
Definition UniquePointer.hpp:27
T make_unique(T... args)

This function is equivalent to calling exchange(nullptr).

See also
exchange(std::nullptr_t)
operator UnownedPointer()

◆ operator UnownedPointer()

template<typename Element , typename Deleter = std::default_delete<Element>>
xentara::utils::atomic::UniquePointer< Element, Deleter >::operator UnownedPointer ( ) const &
noexcept

Atomically fetches the stored object using std::memory_order_seq_cst without taking ownership.

This function does not take ownership of the returned object. To take owneship, you use std::move, which will cause the conversion operator for an std::unique_ptr to be called instead.

Example:

xentara::utils::tools::UnownedPointer<std::string> unownedValue = atomicPointer; // fetches the value without removing it
std::unique_ptr<std::string> removedValue = std::move(atomicPointer); // fetches the value and removes it
A non-owning pointer that is interface compatible with std::unique_ptr.
Definition UnownedPointer.hpp:26
See also
load()
operator std::unique_ptr<Element, Deleter>()

◆ operator=() [1/4]

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::operator= ( const UniquePointer< Element, Deleter > &  )
delete

Deleted assignment opertaor.

◆ operator=() [2/4]

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::operator= ( std::nullptr_t  ) -> void
noexcept

Atomically empties the pointer using std::memory_order_seq_cst.

Any previously held object will be deleted.

◆ operator=() [3/4]

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::operator= ( std::unique_ptr< Element, Deleter > &&  value) -> void
noexcept

Atomically transfers an object from an std::unique_ptr using std::memory_order_seq_cst.

Any previously held object will be deleted.

Parameters
valueThe pointer to transfer the object from. Any object the pointer holds will be transferred to the atomic.

◆ operator=() [4/4]

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> &&>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::operator= ( std::unique_ptr< RelatedElement, RelatedDeleter > &&  value) -> void
noexcept

Atomically transfers an object from a related std::unique_ptr using std::memory_order_seq_cst.

Any previously held object will be deleted.

Parameters
valueThe pointer to transfer the object from. Any object the pointer holds will be transferred to the atomic.

◆ store() [1/3]

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::store ( std::nullptr_t  ,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> void
noexcept

Atomically empties the pointer using std::memory_order_seq_cst.

Any previously held object will be deleted.

Parameters
memoryOrderThe memory order to use
See also
std::atomic::store()

◆ store() [2/3]

template<typename Element , typename Deleter = std::default_delete<Element>>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::store ( std::unique_ptr< Element, Deleter >  value,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> void
noexcept

Atomically transfers an object from an std::unique_ptr.

Any previously held object will be deleted.

Parameters
valueThe pointer to transfer the object from. Any object the pointer holds will be transferred to the atomic.
memoryOrderThe memory order to use
See also
std::atomic::store()

◆ store() [3/3]

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> &&>
auto xentara::utils::atomic::UniquePointer< Element, Deleter >::store ( std::unique_ptr< RelatedElement, RelatedDeleter >  value,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> void
noexcept

Atomically transfers an object from a related std::unique_ptr using std::memory_order_seq_cst.

Any previously held object will be deleted.

Parameters
valueThe pointer to transfer the object from. Any object the pointer holds will be transferred to the atomic.
memoryOrderThe memory order to use
See also
std::atomic::store()

Friends And Related Symbol Documentation

◆ operator() [1/4]

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

Tree-way comparison between an atomic unique pointer and a null pointer.

◆ operator() [2/4]

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

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

◆ operator() [3/4]

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

Tree-way comparison between an atomic unique pointer and an unowned pointer.

◆ operator() [4/4]

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

Tree-way comparison between two unowned pointers.

◆ operator==() [1/4]

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

Comparison between an atomic unique pointer and a null pointer.

◆ operator==() [2/4]

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

Comparison between an atomic unique pointer and an std::unique_ptr.

◆ operator==() [3/4]

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

Comparison between an atomic unique pointer and an unowned pointer.

◆ operator==() [4/4]

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

Comparison between two atomic unique pointers.

Member Data Documentation

◆ is_always_lock_free

template<typename Element , typename Deleter = std::default_delete<Element>>
constexpr bool xentara::utils::atomic::UniquePointer< Element, Deleter >::is_always_lock_free
staticconstexpr

Determines whether operations on all objects of thsi class are lock free.

See also
std::atomic::is_lock_free()