Spicy
Public Types | Public Member Functions | List of all members
hilti::rt::Optional< T > Class Template Reference
Inheritance diagram for hilti::rt::Optional< T >:

Public Types

using value_type = T
 

Public Member Functions

constexpr Optional ()=default
 
constexpr Optional (const T &v)
 
constexpr Optional (T &&v)
 
 Optional (const Optional &)=default
 
 Optional (Optional &&) noexcept=default
 
constexpr Optional (hilti::rt::Null) noexcept
 
constexpr Optional (std::in_place_t, auto &&... args)
 
template<typename U >
constexpr Optional (U &&v) requires(std
 
template<typename U >
 Optional (Optional< U > &&v) requires(std
 
 ~Optional ()=default
 
auto hasValue () const noexcept
 
const T & value () const &
 
T & value () &
 
T && value () &&
 
const T && value () const &&
 
const auto & tryValue () const
 
auto valueOr (const T &default_) const &
 
auto & valueOrInit (T &&default_)
 
auto & valueOrInit ()
 
const T & operator* () const &
 
T & operator* () &
 
T && operator* () &&
 
const T && operator* () const &&
 
const T * operator-> () const &
 
T * operator-> () &
 
const T * operator-> () const &&=delete
 
T * operator-> () &&=delete
 
Optionaloperator= (const Optional &)=default
 
Optionaloperator= (Optional &&) noexcept=default
 
Optionaloperator= (hilti::rt::Null) noexcept
 
template<typename U >
Optionaloperator= (U &&v) requires(std
 
template<typename U >
Optionaloperator= (const Optional< U > &v) requires(std
 
template<typename U >
Optionaloperator= (Optional< U > &&v) requires(std
 
template<typename U >
constexpr bool operator== (const Optional< U > &other) const
 
template<typename U >
constexpr bool operator!= (const Optional< U > &other) const
 
template<typename U >
constexpr auto operator< (const Optional< U > &other) const
 
constexpr bool operator== (hilti::rt::Null) const noexcept
 
constexpr bool operator!= (hilti::rt::Null) const noexcept
 

Constructor & Destructor Documentation

◆ Optional() [1/9]

template<typename T >
constexpr hilti::rt::Optional< T >::Optional ( )
constexprdefault

Default constructor creating an unset optional.

◆ Optional() [2/9]

template<typename T >
constexpr hilti::rt::Optional< T >::Optional ( const T &  v)
inlineconstexpr

Constructor from value creating a set optional.

◆ Optional() [3/9]

template<typename T >
constexpr hilti::rt::Optional< T >::Optional ( T &&  v)
inlineconstexpr

Constructor from r-value creating a set optional.

◆ Optional() [4/9]

template<typename T >
hilti::rt::Optional< T >::Optional ( const Optional< T > &  )
default

Copy constructor.

◆ Optional() [5/9]

template<typename T >
hilti::rt::Optional< T >::Optional ( Optional< T > &&  )
defaultnoexcept

Move constructor.

◆ Optional() [6/9]

template<typename T >
constexpr hilti::rt::Optional< T >::Optional ( hilti::rt::Null  )
inlineconstexprnoexcept

Constructor from null value creating an unset optional.

◆ Optional() [7/9]

template<typename T >
constexpr hilti::rt::Optional< T >::Optional ( std::in_place_t  ,
auto &&...  args 
)
inlineconstexpr

In-place constructor forwarding arguments to T's constructor.

◆ Optional() [8/9]

template<typename T >
template<typename U >
constexpr hilti::rt::Optional< T >::Optional ( U &&  v)
inlineconstexpr

Constructor from a value of different type U that's convertible to T.

◆ Optional() [9/9]

template<typename T >
template<typename U >
hilti::rt::Optional< T >::Optional ( Optional< U > &&  v)
inline

Constructor from different optional type containing a value of type U that's convertible to T.

◆ ~Optional()

template<typename T >
hilti::rt::Optional< T >::~Optional ( )
default

Destructor.

Member Function Documentation

◆ hasValue()

template<typename T >
auto hilti::rt::Optional< T >::hasValue ( ) const
inlinenoexcept

Returns true if the optional is set.

◆ operator*() [1/4]

template<typename T >
T& hilti::rt::Optional< T >::operator* ( ) &
inline

Returns the contained value.

Exceptions
optional::Unsetif the optional is not set.

◆ operator*() [2/4]

template<typename T >
T&& hilti::rt::Optional< T >::operator* ( ) &&
inline

Returns the contained value.

Exceptions
optional::Unsetif the optional is not set.

◆ operator*() [3/4]

template<typename T >
const T& hilti::rt::Optional< T >::operator* ( ) const &
inline

Returns the contained value.

Exceptions
optional::Unsetif the optional is not set.

◆ operator*() [4/4]

template<typename T >
const T&& hilti::rt::Optional< T >::operator* ( ) const &&
inline

Returns the contained value.

Exceptions
optional::Unsetif the optional is not set.

◆ operator->() [1/4]

template<typename T >
T* hilti::rt::Optional< T >::operator-> ( ) &
inline

Returns a pointer to the contained value.

Exceptions
optional::Unsetif the optional is not set.

◆ operator->() [2/4]

template<typename T >
T* hilti::rt::Optional< T >::operator-> ( ) &&
delete

Returns a pointer to the contained value.

Exceptions
optional::Unsetif the optional is not set.

◆ operator->() [3/4]

template<typename T >
const T* hilti::rt::Optional< T >::operator-> ( ) const &
inline

Returns a pointer to the contained value.

Exceptions
optional::Unsetif the optional is not set.

◆ operator->() [4/4]

template<typename T >
const T* hilti::rt::Optional< T >::operator-> ( ) const &&
delete

Returns a pointer to the contained value.

Exceptions
optional::Unsetif the optional is not set.

◆ operator=() [1/6]

template<typename T >
Optional& hilti::rt::Optional< T >::operator= ( const Optional< T > &  )
default

Copy assignment operator.

◆ operator=() [2/6]

template<typename T >
template<typename U >
Optional& hilti::rt::Optional< T >::operator= ( const Optional< U > &  v)
inline

Assigns from a value of different optional type containing a value of type U that's convertible to T.

◆ operator=() [3/6]

template<typename T >
Optional& hilti::rt::Optional< T >::operator= ( hilti::rt::Null  )
inlinenoexcept

Assigns from null value, resetting the optional.

◆ operator=() [4/6]

template<typename T >
Optional& hilti::rt::Optional< T >::operator= ( Optional< T > &&  )
defaultnoexcept

Move assignment operator.

◆ operator=() [5/6]

template<typename T >
template<typename U >
Optional& hilti::rt::Optional< T >::operator= ( Optional< U > &&  v)
inline

Assigns from a different optional type containing a value of type U that's convertible to T.

◆ operator=() [6/6]

template<typename T >
template<typename U >
Optional& hilti::rt::Optional< T >::operator= ( U &&  v)
inline

Assigns from a value of different type U that's convertible to T.

◆ tryValue()

template<typename T >
const auto& hilti::rt::Optional< T >::tryValue ( ) const
inline

Returns the contained value or throws optional::Unset if not set.

Note that this method differs from value() in that it throws a different exception that's not derived from RuntimeError. This is for catching accesses to a unset optional that are deemed legitimate within the caller's context.

◆ value() [1/4]

template<typename T >
T& hilti::rt::Optional< T >::value ( ) &
inline

Returns the contained value.

Exceptions
optional::Unsetif the optional is not set.

◆ value() [2/4]

template<typename T >
T&& hilti::rt::Optional< T >::value ( ) &&
inline

Returns the contained value.

Exceptions
optional::Unsetif the optional is not set.

◆ value() [3/4]

template<typename T >
const T& hilti::rt::Optional< T >::value ( ) const &
inline

Returns the contained value.

Exceptions
optional::Unsetif the optional is not set.

◆ value() [4/4]

template<typename T >
const T&& hilti::rt::Optional< T >::value ( ) const &&
inline

Returns the contained value.

Exceptions
optional::Unsetif the optional is not set.

◆ valueOr()

template<typename T >
auto hilti::rt::Optional< T >::valueOr ( const T &  default_) const &
inline

Returns the contained value or a default if not set.

◆ valueOrInit() [1/2]

template<typename T >
auto& hilti::rt::Optional< T >::valueOrInit ( )
inline

Returns the contained value, potentially first initializing it with a default-constructed value if not already set.

◆ valueOrInit() [2/2]

template<typename T >
auto& hilti::rt::Optional< T >::valueOrInit ( T &&  default_)
inline

Returns the contained value, potentially first initializing it with a default if not already set.

Parameters
default_the default value to initialize with if not set yet

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