tenno 0.1.0
Loading...
Searching...
No Matches
tenno::optional< T > Class Template Reference

An optional value. More...

#include <optional.hpp>

Public Types

using value_type = T
 The type of the optional value.
 

Public Member Functions

constexpr optional () noexcept
 Constructs an optional that does not contain a value.
 
constexpr optional (T value) noexcept
 
optional operator= (T &value) noexcept
 
constexpr T operator-> () const noexcept
 
constexpr T operator* () const noexcept
 
constexpr bool has_value () const noexcept
 
constexpr T value () const noexcept
 
constexpr T value_or (const T &other) const noexcept
 Returns the value of the optional or a default value.
 
void swap (optional &other) noexcept
 Swaps the optional with another optional.
 
void reset () noexcept
 
template<class... Args>
T & emplace (Args &&...args)
 Constructs the value in place.
 

Detailed Description

template<typename T>
class tenno::optional< T >

An optional value.

Template Parameters
TThe type of the optional value The optional class template manages an optional contained value, i.e. a value that may or may not be present. A common use case for optional is the return value of a function that may fail. It is also usefult for costly-to-construct objects since it avoids the need to construct them until they are needed.

Definition at line 23 of file optional.hpp.

Member Typedef Documentation

◆ value_type

template<typename T >
using tenno::optional< T >::value_type = T

The type of the optional value.

Definition at line 29 of file optional.hpp.

Constructor & Destructor Documentation

◆ optional() [1/2]

template<typename T >
tenno::optional< T >::optional ( )
inlineconstexprnoexcept

Constructs an optional that does not contain a value.

Definition at line 34 of file optional.hpp.

◆ optional() [2/2]

template<typename T >
tenno::optional< T >::optional ( T value)
inlineconstexprnoexcept

Definition at line 46 of file optional.hpp.

Member Function Documentation

◆ emplace()

template<typename T >
template<class... Args>
T & tenno::optional< T >::emplace ( Args &&... args)
inline

Constructs the value in place.

Template Parameters
ArgsThe types of the arguments to construct the value
Parameters
argsThe arguments to construct the value
Returns
T& The constructed value

Definition at line 114 of file optional.hpp.

◆ has_value()

template<typename T >
bool tenno::optional< T >::has_value ( ) const
inlineconstexprnoexcept

Definition at line 65 of file optional.hpp.

◆ operator*()

template<typename T >
T tenno::optional< T >::operator* ( ) const
inlineconstexprnoexcept

Definition at line 60 of file optional.hpp.

◆ operator->()

template<typename T >
T tenno::optional< T >::operator-> ( ) const
inlineconstexprnoexcept

Definition at line 55 of file optional.hpp.

◆ operator=()

template<typename T >
optional tenno::optional< T >::operator= ( T & value)
inlinenoexcept

Definition at line 50 of file optional.hpp.

◆ reset()

template<typename T >
void tenno::optional< T >::reset ( )
inlinenoexcept

Definition at line 100 of file optional.hpp.

◆ swap()

template<typename T >
void tenno::optional< T >::swap ( optional< T > & other)
inlinenoexcept

Swaps the optional with another optional.

Parameters
otherThe other optional to swap with

Definition at line 94 of file optional.hpp.

◆ value()

template<typename T >
T tenno::optional< T >::value ( ) const
inlineconstexprnoexcept

Definition at line 70 of file optional.hpp.

◆ value_or()

template<typename T >
T tenno::optional< T >::value_or ( const T & other) const
inlineconstexprnoexcept

Returns the value of the optional or a default value.

Parameters
otherThe default value to return if the optional does not have a value
Returns
T The value of the optional or the default value

Definition at line 82 of file optional.hpp.

Field Documentation

◆ _value

template<typename T >
T tenno::optional< T >::_value

Definition at line 124 of file optional.hpp.


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