ORIGINAL
Loading...
Searching...
No Matches
original::alternative< TYPE > Class Template Reference

A type-safe container that may or may not contain a value. More...

#include <optional.h>

Collaboration diagram for original::alternative< TYPE >:
Collaboration graph

Public Member Functions

 alternative ()
 Constructs an empty alternative.
 
template<typename... Args>
 alternative (Args &&... args)
 Constructs an alternative containing a value.
 
 alternative (const alternative &other)
 Copy constructor.
 
alternativeoperator= (const alternative &other)
 Copy assignment.
 
 alternative (alternative &&other) noexcept
 Move constructor.
 
alternativeoperator= (alternative &&other) noexcept
 Move assignment.
 
const TYPE & operator* () const
 Const value access.
 
TYPE & operator* ()
 Mutable value access.
 
const TYPE * operator-> () const
 Const member access.
 
TYPE * operator-> ()
 Mutable member access.
 
const TYPE * get () const
 Gets const pointer to value.
 
TYPE * get ()
 Gets mutable pointer to value.
 
void reset () noexcept
 Resets to empty state.
 
template<typename... Args>
void emplace (Args &&... args)
 Constructs value in-place.
 
void set (const TYPE &t)
 Sets value by copy.
 
 operator bool () const
 Checks if contains a value.
 
bool hasValue () const
 Checks if contains a value.
 
 ~alternative ()
 Destructor.
 

Detailed Description

template<typename TYPE>
class original::alternative< TYPE >

A type-safe container that may or may not contain a value.

Specialization for void type alternative.

Template Parameters
TYPEThe type of value to store

This class provides a way to represent optional values without using pointers. It can either contain a value of type TYPE or be empty. The empty state is represented using original::none from types.h.

Example usage:

alternative<int> opt; // Empty state
alternative<int> opt2(42); // Contains value 42
if (opt2) { // Check if has value
int val = *opt2; // Access the value
}
A type-safe container that may or may not contain a value.
Definition optional.h:45

Represents a simple boolean flag indicating presence or absence of a value without storing actual data. Useful for signaling states without associated data.

Constructor & Destructor Documentation

◆ alternative() [1/4]

template<typename TYPE >
original::alternative< TYPE >::alternative ( )
explicit

Constructs an empty alternative.

Postcondition
hasValue() == false

◆ alternative() [2/4]

template<typename TYPE >
template<typename... Args>
original::alternative< TYPE >::alternative ( Args &&... args)
explicit

Constructs an alternative containing a value.

Template Parameters
ArgsArgument types for TYPE construction
Parameters
argsArguments to forward to TYPE constructor
Postcondition
hasValue() == true

◆ alternative() [3/4]

template<typename TYPE >
original::alternative< TYPE >::alternative ( const alternative< TYPE > & other)

Copy constructor.

Parameters
otherAlternative to copy from
Postcondition
hasValue() == other.hasValue()

◆ alternative() [4/4]

template<typename TYPE >
original::alternative< TYPE >::alternative ( alternative< TYPE > && other)
noexcept

Move constructor.

Parameters
otherAlternative to move from
Postcondition
other is left in valid but unspecified state

◆ ~alternative()

template<typename TYPE >
original::alternative< TYPE >::~alternative ( )

Destructor.

Note
Properly destroys contained value if present

Member Function Documentation

◆ emplace()

template<typename TYPE >
template<typename... Args>
void original::alternative< TYPE >::emplace ( Args &&... args)

Constructs value in-place.

Template Parameters
ArgsArgument types for TYPE construction
Parameters
argsArguments to forward to TYPE constructor
Postcondition
hasValue() == true

◆ get() [1/2]

template<typename TYPE >
TYPE * original::alternative< TYPE >::get ( )

Gets mutable pointer to value.

Returns
Pointer to value or nullptr if empty

◆ get() [2/2]

template<typename TYPE >
const TYPE * original::alternative< TYPE >::get ( ) const

Gets const pointer to value.

Returns
Pointer to value or nullptr if empty

◆ hasValue()

template<typename TYPE >
bool original::alternative< TYPE >::hasValue ( ) const
nodiscard

Checks if contains a value.

Returns
true if contains value, false if empty

◆ operator bool()

template<typename TYPE >
original::alternative< TYPE >::operator bool ( ) const
explicit

Checks if contains a value.

Returns
true if contains value, false if empty

◆ operator*() [1/2]

template<typename TYPE >
TYPE & original::alternative< TYPE >::operator* ( )

Mutable value access.

Returns
Reference to contained value
Exceptions
valueErrorif empty

◆ operator*() [2/2]

template<typename TYPE >
const TYPE & original::alternative< TYPE >::operator* ( ) const

Const value access.

Returns
Const reference to contained value
Exceptions
valueErrorif empty

◆ operator->() [1/2]

template<typename TYPE >
TYPE * original::alternative< TYPE >::operator-> ( )

Mutable member access.

Returns
Pointer to contained value
Exceptions
valueErrorif empty

◆ operator->() [2/2]

template<typename TYPE >
const TYPE * original::alternative< TYPE >::operator-> ( ) const

Const member access.

Returns
Const pointer to contained value
Exceptions
valueErrorif empty

◆ operator=() [1/2]

template<typename TYPE >
original::alternative< TYPE > & original::alternative< TYPE >::operator= ( alternative< TYPE > && other)
noexcept

Move assignment.

Parameters
otherAlternative to move from
Returns
Reference to this alternative
Postcondition
other is left in valid but unspecified state

◆ operator=() [2/2]

template<typename TYPE >
original::alternative< TYPE > & original::alternative< TYPE >::operator= ( const alternative< TYPE > & other)

Copy assignment.

Parameters
otherAlternative to copy from
Returns
Reference to this alternative
Postcondition
hasValue() == other.hasValue()

◆ reset()

template<typename TYPE >
void original::alternative< TYPE >::reset ( )
noexcept

Resets to empty state.

Postcondition
hasValue() == false

◆ set()

template<typename TYPE >
void original::alternative< TYPE >::set ( const TYPE & t)

Sets value by copy.

Parameters
tValue to copy
Postcondition
hasValue() == true

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