xentara-utils v1.2.1
Xentara utilities library
Loading...
Searching...
No Matches
xentara::utils::atomic::Optional< Type > Class Template Reference

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

#include <atomic/Optional.hpp>

Public Member Functions

constexpr Optional () noexcept=default
 Default constructor.
 
constexpr Optional (std::optional< Type > value) noexcept
 Constructor that initializes the value.
 
constexpr Optional (Type value) noexcept
 Constructor that initializes the value to a real value.
 
constexpr Optional (std::nullopt_t) noexcept
 Constructor that initializes the value to std::nullopt.
 
auto operator= (std::optional< Type > value) noexcept -> std::optional< Type >
 Atomically stores the value using std::memory_order_seq_cst.
 
auto operator= (Type value) noexcept -> std::optional< Type >
 Atomically stores a real value using std::memory_order_seq_cst.
 
auto operator= (std::nullopt_t) noexcept -> std::optional< Type >
 Atomically stores an std::nullopt value using std::memory_order_seq_cst.
 
 operator std::optional< Type > () const noexcept
 Atomically loads the value using std::memory_order_seq_cst.
 
auto load () const noexcept -> std::optional< Type >
 Atomically loads the value.
 
auto load (std::memory_order memoryOrder) const noexcept -> std::optional< Type >
 Atomically loads the value.
 
auto store (std::optional< Type > value) noexcept -> void
 Atomically stores the value.
 
auto store (std::optional< Type > value, std::memory_order memoryOrder) noexcept -> void
 Atomically stores the value.
 
auto store (Type value) noexcept -> void
 Atomically stores a real value.
 
auto store (Type value, std::memory_order memoryOrder) noexcept -> void
 Atomically stores a real value.
 
auto store (std::nullopt_t) noexcept -> void
 Atomically stores an std::nullopt.
 
auto store (std::nullopt_t, std::memory_order memoryOrder) noexcept -> void
 Atomically stores an std::nullopt.
 
auto exchange (std::optional< Type > newValue) noexcept -> std::optional< Type >
 Atomically exchanges the value with a new value.
 
auto exchange (std::optional< Type > newValue, std::memory_order memoryOrder) noexcept -> std::optional< Type >
 Atomically exchanges the value with a new value.
 
auto exchange (Type newValue) noexcept -> std::optional< Type >
 Atomically exchanges the value with a real value.
 
auto exchange (Type newValue, std::memory_order memoryOrder) noexcept -> std::optional< Type >
 Atomically exchanges the value with a real value.
 
auto exchange (std::nullopt_t) noexcept -> std::optional< Type >
 Atomically exchanges the value with an std::nullopt.
 
auto exchange (std::nullopt_t, std::memory_order memoryOrder) noexcept -> std::optional< Type >
 Atomically exchanges the value with an std::nullopt.
 
auto compare_exchange_weak (std::optional< Type > &expectedValue, std::optional< Type > newValue) noexcept -> bool
 Conditionally atomically exchanges the value with a new value.
 
auto compare_exchange_weak (std::optional< Type > &expectedValue, std::optional< Type > newValue, std::memory_order memoryOrder) noexcept -> bool
 Conditionally atomically exchanges the value with a new value.
 
auto compare_exchange_weak (std::optional< Type > &expectedValue, std::optional< Type > newValue, std::memory_order memoryOrderForSuccess, std::memory_order memoryOrderForFailure) noexcept -> bool
 Conditionally atomically exchanges the value with a new value.
 
auto compare_exchange_weak (std::optional< Type > &expectedValue, Type newValue) noexcept -> bool
 Conditionally atomically exchanges the value with a real value.
 
auto compare_exchange_weak (std::optional< Type > &expectedValue, Type newValue, std::memory_order memoryOrder) noexcept -> bool
 Conditionally atomically exchanges the value with a real value.
 
auto compare_exchange_weak (std::optional< Type > &expectedValue, Type newValue, std::memory_order memoryOrderForSuccess, std::memory_order memoryOrderForFailure) noexcept -> bool
 Conditionally atomically exchanges the value with a real value.
 
auto compare_exchange_weak (std::optional< Type > &expectedValue, std::nullopt_t) noexcept -> bool
 Conditionally atomically exchanges the value with a new value.
 
auto compare_exchange_weak (std::optional< Type > &expectedValue, std::nullopt_t, std::memory_order memoryOrder) noexcept -> bool
 Conditionally atomically exchanges the value with a new value.
 
auto compare_exchange_weak (std::optional< Type > &expectedValue, std::nullopt_t, std::memory_order memoryOrderForSuccess, std::memory_order memoryOrderForFailure) noexcept -> bool
 Conditionally atomically exchanges the value with a new value.
 
auto compare_exchange_strong (std::optional< Type > &expectedValue, std::optional< Type > newValue) noexcept -> bool
 Conditionally atomically exchanges the value with a new value.
 
auto compare_exchange_strong (std::optional< Type > &expectedValue, std::optional< Type > newValue, std::memory_order memoryOrder) noexcept -> bool
 Conditionally atomically exchanges the value with a new value.
 
auto compare_exchange_strong (std::optional< Type > &expectedValue, std::optional< Type > newValue, std::memory_order memoryOrderForSuccess, std::memory_order memoryOrderForFailure) noexcept -> bool
 Conditionally atomically exchanges the value with a new value.
 
auto compare_exchange_strong (std::optional< Type > &expectedValue, Type newValue) noexcept -> bool
 Conditionally atomically exchanges the value with a real value.
 
auto compare_exchange_strong (std::optional< Type > &expectedValue, Type newValue, std::memory_order memoryOrder) noexcept -> bool
 Conditionally atomically exchanges the value with a real value.
 
auto compare_exchange_strong (std::optional< Type > &expectedValue, Type newValue, std::memory_order memoryOrderForSuccess, std::memory_order memoryOrderForFailure) noexcept -> bool
 Conditionally atomically exchanges the value with a real value.
 
auto compare_exchange_strong (std::optional< Type > &expectedValue, std::nullopt_t) noexcept -> bool
 Conditionally atomically exchanges the value with a new value.
 
auto compare_exchange_strong (std::optional< Type > &expectedValue, std::nullopt_t, std::memory_order memoryOrder) noexcept -> bool
 Conditionally atomically exchanges the value with a new value.
 
auto compare_exchange_strong (std::optional< Type > &expectedValue, std::nullopt_t, std::memory_order memoryOrderForSuccess, std::memory_order memoryOrderForFailure) noexcept -> bool
 Conditionally atomically exchanges the value with a new value.
 
auto is_lock_free () const noexcept -> bool
 Determines whether operations on this object are lock free.
 
 Optional (const Optional &)=delete
 Deleted copy constructor.
 
auto operator= (const Optional &)=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.
 

Detailed Description

template<typename Type>
class xentara::utils::atomic::Optional< Type >

An atomic version of std::optional.

This class allows defining atomics that operate contain [std::optional]s. Normal [std::atomic]s cannot contain [std::optional]s, because std::optional is not guaranteed to be trivially copyable.

Requirements:
Type must be suitable for use in an std::atomic. Additionally Type must be trivially destructible.
Note
Atomic optionals for IEEE-754 floating point types (float, double, long double) use a special internal encoding to increase the chance that atomic optionals for these types are lock-free. As a side-effect, atomic::Optional for these types may not preserve the exact encoding of certain special signalling NaN values. This is only relevant if you need to distinguish between different binary encodings of signalling NaNs. The standard signaling NaN returned by std::numeric_limits<Type>::signaling_NaN as well as its negative counterpart are guaranteed to be preserved exactly, however.

Constructor & Destructor Documentation

◆ Optional() [1/5]

template<typename Type >
constexpr xentara::utils::atomic::Optional< Type >::Optional ( )
constexprdefaultnoexcept

Default constructor.

This constructor creates an object containing std::nullopt.

◆ Optional() [2/5]

template<typename Type >
constexpr xentara::utils::atomic::Optional< Type >::Optional ( std::optional< Type >  value)
constexprnoexcept

Constructor that initializes the value.

◆ Optional() [3/5]

template<typename Type >
constexpr xentara::utils::atomic::Optional< Type >::Optional ( Type  value)
constexprnoexcept

Constructor that initializes the value to a real value.

◆ Optional() [4/5]

template<typename Type >
constexpr xentara::utils::atomic::Optional< Type >::Optional ( std::nullopt_t  )
constexprnoexcept

Constructor that initializes the value to std::nullopt.

This constructor creates an object containing std::nullopt. It is equivalient to the default constructor.

◆ Optional() [5/5]

template<typename Type >
xentara::utils::atomic::Optional< Type >::Optional ( const Optional< Type > &  )
delete

Deleted copy constructor.

Member Function Documentation

◆ compare_exchange_strong() [1/9]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::compare_exchange_strong ( std::optional< Type > &  expectedValue,
std::nullopt_t   
) -> bool
noexcept

Conditionally atomically exchanges the value with a new value.

See also
std::atomic::compare_exchange_strong()

◆ compare_exchange_strong() [2/9]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::compare_exchange_strong ( std::optional< Type > &  expectedValue,
std::nullopt_t  ,
std::memory_order  memoryOrder 
) -> bool
noexcept

Conditionally atomically exchanges the value with a new value.

See also
std::atomic::compare_exchange_strong()

◆ compare_exchange_strong() [3/9]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::compare_exchange_strong ( std::optional< Type > &  expectedValue,
std::nullopt_t  ,
std::memory_order  memoryOrderForSuccess,
std::memory_order  memoryOrderForFailure 
) -> bool
noexcept

Conditionally atomically exchanges the value with a new value.

See also
std::atomic::compare_exchange_strong()

◆ compare_exchange_strong() [4/9]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::compare_exchange_strong ( std::optional< Type > &  expectedValue,
std::optional< Type >  newValue 
) -> bool
noexcept

Conditionally atomically exchanges the value with a new value.

See also
std::atomic::compare_exchange_strong()

◆ compare_exchange_strong() [5/9]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::compare_exchange_strong ( std::optional< Type > &  expectedValue,
std::optional< Type >  newValue,
std::memory_order  memoryOrder 
) -> bool
noexcept

Conditionally atomically exchanges the value with a new value.

See also
std::atomic::compare_exchange_strong()

◆ compare_exchange_strong() [6/9]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::compare_exchange_strong ( std::optional< Type > &  expectedValue,
std::optional< Type >  newValue,
std::memory_order  memoryOrderForSuccess,
std::memory_order  memoryOrderForFailure 
) -> bool
noexcept

Conditionally atomically exchanges the value with a new value.

See also
std::atomic::compare_exchange_strong()

◆ compare_exchange_strong() [7/9]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::compare_exchange_strong ( std::optional< Type > &  expectedValue,
Type  newValue 
) -> bool
noexcept

Conditionally atomically exchanges the value with a real value.

See also
std::atomic::compare_exchange_strong()

◆ compare_exchange_strong() [8/9]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::compare_exchange_strong ( std::optional< Type > &  expectedValue,
Type  newValue,
std::memory_order  memoryOrder 
) -> bool
noexcept

Conditionally atomically exchanges the value with a real value.

See also
std::atomic::compare_exchange_strong()

◆ compare_exchange_strong() [9/9]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::compare_exchange_strong ( std::optional< Type > &  expectedValue,
Type  newValue,
std::memory_order  memoryOrderForSuccess,
std::memory_order  memoryOrderForFailure 
) -> bool
noexcept

Conditionally atomically exchanges the value with a real value.

See also
std::atomic::compare_exchange_strong()

◆ compare_exchange_weak() [1/9]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::compare_exchange_weak ( std::optional< Type > &  expectedValue,
std::nullopt_t   
) -> bool
noexcept

Conditionally atomically exchanges the value with a new value.

See also
std::atomic::compare_exchange_weak()

◆ compare_exchange_weak() [2/9]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::compare_exchange_weak ( std::optional< Type > &  expectedValue,
std::nullopt_t  ,
std::memory_order  memoryOrder 
) -> bool
noexcept

Conditionally atomically exchanges the value with a new value.

See also
std::atomic::compare_exchange_weak()

◆ compare_exchange_weak() [3/9]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::compare_exchange_weak ( std::optional< Type > &  expectedValue,
std::nullopt_t  ,
std::memory_order  memoryOrderForSuccess,
std::memory_order  memoryOrderForFailure 
) -> bool
noexcept

Conditionally atomically exchanges the value with a new value.

See also
std::atomic::compare_exchange_weak()

◆ compare_exchange_weak() [4/9]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::compare_exchange_weak ( std::optional< Type > &  expectedValue,
std::optional< Type >  newValue 
) -> bool
noexcept

Conditionally atomically exchanges the value with a new value.

See also
std::atomic::compare_exchange_weak()

◆ compare_exchange_weak() [5/9]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::compare_exchange_weak ( std::optional< Type > &  expectedValue,
std::optional< Type >  newValue,
std::memory_order  memoryOrder 
) -> bool
noexcept

Conditionally atomically exchanges the value with a new value.

See also
std::atomic::compare_exchange_weak()

◆ compare_exchange_weak() [6/9]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::compare_exchange_weak ( std::optional< Type > &  expectedValue,
std::optional< Type >  newValue,
std::memory_order  memoryOrderForSuccess,
std::memory_order  memoryOrderForFailure 
) -> bool
noexcept

Conditionally atomically exchanges the value with a new value.

See also
std::atomic::compare_exchange_weak()

◆ compare_exchange_weak() [7/9]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::compare_exchange_weak ( std::optional< Type > &  expectedValue,
Type  newValue 
) -> bool
noexcept

Conditionally atomically exchanges the value with a real value.

See also
std::atomic::compare_exchange_weak()

◆ compare_exchange_weak() [8/9]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::compare_exchange_weak ( std::optional< Type > &  expectedValue,
Type  newValue,
std::memory_order  memoryOrder 
) -> bool
noexcept

Conditionally atomically exchanges the value with a real value.

See also
std::atomic::compare_exchange_weak()

◆ compare_exchange_weak() [9/9]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::compare_exchange_weak ( std::optional< Type > &  expectedValue,
Type  newValue,
std::memory_order  memoryOrderForSuccess,
std::memory_order  memoryOrderForFailure 
) -> bool
noexcept

Conditionally atomically exchanges the value with a real value.

See also
std::atomic::compare_exchange_weak()

◆ exchange() [1/6]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::exchange ( std::nullopt_t  ) -> std::optional<Type>
noexcept

Atomically exchanges the value with an std::nullopt.

See also
std::atomic::exchange()

◆ exchange() [2/6]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::exchange ( std::nullopt_t  ,
std::memory_order  memoryOrder 
) -> std::optional<Type>
noexcept

Atomically exchanges the value with an std::nullopt.

See also
std::atomic::exchange()

◆ exchange() [3/6]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::exchange ( std::optional< Type >  newValue) -> std::optional<Type>
noexcept

Atomically exchanges the value with a new value.

See also
std::atomic::exchange()

◆ exchange() [4/6]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::exchange ( std::optional< Type >  newValue,
std::memory_order  memoryOrder 
) -> std::optional<Type>
noexcept

Atomically exchanges the value with a new value.

See also
std::atomic::exchange()

◆ exchange() [5/6]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::exchange ( Type  newValue) -> std::optional<Type>
noexcept

Atomically exchanges the value with a real value.

See also
std::atomic::exchange()

◆ exchange() [6/6]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::exchange ( Type  newValue,
std::memory_order  memoryOrder 
) -> std::optional<Type>
noexcept

Atomically exchanges the value with a real value.

See also
std::atomic::exchange()

◆ is_lock_free()

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::is_lock_free ( ) const -> bool
noexcept

Determines whether operations on this object are lock free.

See also
std::atomic::is_lock_free()

◆ load() [1/2]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::load ( ) const -> std::optional<Type>
noexcept

Atomically loads the value.

See also
std::atomic::load()

◆ load() [2/2]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::load ( std::memory_order  memoryOrder) const -> std::optional<Type>
noexcept

Atomically loads the value.

See also
std::atomic::load()

◆ operator std::optional< Type >()

template<typename Type >
xentara::utils::atomic::Optional< Type >::operator std::optional< Type > ( ) const
noexcept

Atomically loads the value using std::memory_order_seq_cst.

◆ operator=() [1/4]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::operator= ( const Optional< Type > &  )
delete

Deleted assignment opertaor.

◆ operator=() [2/4]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::operator= ( std::nullopt_t  ) -> std::optional<Type>
noexcept

Atomically stores an std::nullopt value using std::memory_order_seq_cst.

◆ operator=() [3/4]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::operator= ( std::optional< Type >  value) -> std::optional<Type>
noexcept

Atomically stores the value using std::memory_order_seq_cst.

◆ operator=() [4/4]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::operator= ( Type  value) -> std::optional<Type>
noexcept

Atomically stores a real value using std::memory_order_seq_cst.

◆ store() [1/6]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::store ( std::nullopt_t  ) -> void
noexcept

Atomically stores an std::nullopt.

See also
std::atomic::store()

◆ store() [2/6]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::store ( std::nullopt_t  ,
std::memory_order  memoryOrder 
) -> void
noexcept

Atomically stores an std::nullopt.

See also
std::atomic::store()

◆ store() [3/6]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::store ( std::optional< Type >  value) -> void
noexcept

Atomically stores the value.

See also
std::atomic::store()

◆ store() [4/6]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::store ( std::optional< Type >  value,
std::memory_order  memoryOrder 
) -> void
noexcept

Atomically stores the value.

See also
std::atomic::store()

◆ store() [5/6]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::store ( Type  value) -> void
noexcept

Atomically stores a real value.

See also
std::atomic::store()

◆ store() [6/6]

template<typename Type >
auto xentara::utils::atomic::Optional< Type >::store ( Type  value,
std::memory_order  memoryOrder 
) -> void
noexcept

Atomically stores a real value.

See also
std::atomic::store()

Member Data Documentation

◆ is_always_lock_free

template<typename Type >
constexpr bool xentara::utils::atomic::Optional< Type >::is_always_lock_free
staticconstexpr

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

See also
std::atomic::is_lock_free()