Qx v0.6
Qt Extensions Library
Loading...
Searching...
No Matches
Qx::SetOnce< T, C > 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, C &&comp=C())
 
bool isSet () const
 
 operator bool () const
 
const T & operator* () const
 
const T * operator-> () const
 
SetOnce< T, C > & operator= (const T &value)
 
void reset ()
 
const T & value () const
 

Detailed Description

template<typename T, class C>
requires std::assignable_from<T&, T> && comparator<C, T>
class Qx::SetOnce< T, C >

The optional C template parameter (defaults to void) can be used to provide a comparator (such as std::equal_to), which is then used to reject assignment if the passed value is the same as the containers default.

See also
operator=().

Constructor & Destructor Documentation

◆ SetOnce()

template<typename T , class C >
Qx::SetOnce< T, C >::SetOnce ( T initial,
C && comp = C() )
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.

When C is not void, comp is used to compare the input value to the container's default value when performing an assignment.

See also
operator=(const T& value).

Member Function Documentation

◆ isSet()

template<typename T , class C >
Qx::SetOnce< T, C >::isSet ( ) const
inline

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

◆ operator bool()

template<typename T , class C >
Qx::SetOnce< T, C >::operator bool ( ) const
inlineexplicit

Produces the boolean value true if the container is set; otherwise, produces false.

◆ operator*()

template<typename T , class C >
const T & Qx::SetOnce< T, C >::operator* ( ) const
inline

Same as value().

◆ operator->()

template<typename T , class C >
const T * Qx::SetOnce< T, C >::operator-> ( ) const
inline

Allows access to members of T for the value of the container.

◆ operator=()

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

Sets the value of the container to value. If C is not void and value is the same as the container's default value, the container is not considered to be set.

To clarify:

  • C = void: Any assignment causes the container to be considered set.
  • C satisfies Qx::comparator<C, T> : Only assignment of a value other than the default causes the container to be considered set.

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

See also
reset().

◆ reset()

template<typename T , class C >
void Qx::SetOnce< T, C >::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 C >
const T & Qx::SetOnce< T, C >::value ( ) const
inline

Returns the current value of the container.


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