Qx v0.5.7
Qt Extensions Library
Loading...
Searching...
No Matches
Qx::SetOnce< T, CompareEq > Class Template Reference

The SetOnce template class acts as a container for a value that can only be set once. More...

#include <qx/core/qx-setonce.h>

Public Member Functions

 SetOnce (T initial, const CompareEq &comp=CompareEq())
 
bool isSet () const
 
SetOnce< T, CompareEq > & operator= (const T &value)
 
void reset ()
 
const T & value () const
 

Detailed Description

template<typename T, class CompareEq = std::equal_to<T>>
requires std::is_assignable_v<T&, T> && Qx::defines_call_for_s<CompareEq, bool, T, T>
class Qx::SetOnce< T, CompareEq >

The optional CompareEq template parameter can be used to provide a custom compare-equal function object type.

Constructor & Destructor Documentation

◆ SetOnce()

template<typename T , class CompareEq = std::equal_to<T>>
Qx::SetOnce< T, CompareEq >::SetOnce ( T initial,
const CompareEq & comp = CompareEq() )
inline

Creates a SetOnce container that holds the initial value initial.

The container is initially unset and only holds this value until it is set.

Optionally, a custom compare-equal function can be provided through comp, which is used to determine whether or not an assigned value is different from the container's initial value.

See also
operator=(const T& value).

Member Function Documentation

◆ isSet()

template<typename T , class CompareEq = std::equal_to<T>>
Qx::SetOnce< T, CompareEq >::isSet ( ) const
inline

Returns true if the containers value has been set; otherwise returns false.

◆ operator=()

template<typename T , class CompareEq = std::equal_to<T>>
SetOnce< T, CompareEq > & Qx::SetOnce< T, CompareEq >::operator= ( const T & value)
inline

Sets the value of the container to value, if it is different from its initial value.

Once the containers value has been set it cannot be changed again until it is reset.

See also
reset().

◆ reset()

template<typename T , class CompareEq = std::equal_to<T>>
void Qx::SetOnce< T, CompareEq >::reset ( )
inline

Resets the container to its initial state.

The containers value will revert to the value specified in its constructor and will be considered unset.

See also
operator=().

◆ value()

template<typename T , class CompareEq = std::equal_to<T>>
const T & Qx::SetOnce< T, CompareEq >::value ( ) const
inline

Returns the current value of the container.


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