swift
Loading...
Searching...
No Matches
swift::misc::Optional< T > Class Template Reference

Own implementation of std::optional. More...

#include <optional.h>

Public Member Functions

 Optional () noexcept=default
 Default constructor.
 Optional (T value) noexcept(std::is_nothrow_move_constructible_v< T >)
 Construct from a value.
 Optional (std::nullptr_t) noexcept
 Construct from a nullptr, equivalent to default constructor.
 Optional (const Optional &other) noexcept(std::is_nothrow_copy_constructible_v< T >)
 Copy constructor.
 Optional (Optional &&other) noexcept(std::is_nothrow_move_constructible_v< T >)
 Move constructor.
Optional & operator= (std::nullptr_t) noexcept
 Assign a nullptr.
Optional & operator= (const Optional &other) noexcept(std::is_nothrow_copy_constructible_v< T >)
 Copy assignment.
Optional & operator= (Optional &&other) noexcept(std::is_nothrow_move_constructible_v< T >)
 Move assignment.
 ~Optional ()
 Destructor.
 operator bool () const noexcept
 Explicit cast to bool, true if this Optional contains a value.
void reset () noexcept
 If object is valid, destroy to make it invalid.
T & operator* ()
 Dereference operator, returns reference to contained value, undefined if there is no value contained.
const T & operator* () const
 Dereference operator, returns reference to contained value, undefined if there is no value contained.
T * operator-> ()
 Indirection operator, returns pointer to contained value, undefined if there is no value contained.
const T * operator-> () const
 Indirection operator, returns pointer to contained value, undefined if there is no value contained.

Detailed Description

template<typename T>
class swift::misc::Optional< T >

Own implementation of std::optional.

Needed to work around lack of C++20 copyable lambda functions.

Definition at line 22 of file optional.h.

Constructor & Destructor Documentation

◆ Optional() [1/4]

template<typename T>
swift::misc::Optional< T >::Optional ( T value)
inlinenoexcept

Construct from a value.

Definition at line 29 of file optional.h.

◆ Optional() [2/4]

template<typename T>
swift::misc::Optional< T >::Optional ( std::nullptr_t )
inlinenoexcept

Construct from a nullptr, equivalent to default constructor.

Definition at line 36 of file optional.h.

◆ Optional() [3/4]

template<typename T>
swift::misc::Optional< T >::Optional ( const Optional< T > & other)
inlinenoexcept

Copy constructor.

Definition at line 39 of file optional.h.

◆ Optional() [4/4]

template<typename T>
swift::misc::Optional< T >::Optional ( Optional< T > && other)
inlinenoexcept

Move constructor.

Definition at line 49 of file optional.h.

◆ ~Optional()

template<typename T>
swift::misc::Optional< T >::~Optional ( )
inline

Destructor.

Definition at line 90 of file optional.h.

Member Function Documentation

◆ operator bool()

template<typename T>
swift::misc::Optional< T >::operator bool ( ) const
inlineexplicitnoexcept

Explicit cast to bool, true if this Optional contains a value.

Definition at line 99 of file optional.h.

◆ operator*() [1/2]

template<typename T>
T & swift::misc::Optional< T >::operator* ( )
inline

Dereference operator, returns reference to contained value, undefined if there is no value contained.

Definition at line 112 of file optional.h.

◆ operator*() [2/2]

template<typename T>
const T & swift::misc::Optional< T >::operator* ( ) const
inline

Dereference operator, returns reference to contained value, undefined if there is no value contained.

Definition at line 115 of file optional.h.

◆ operator->() [1/2]

template<typename T>
T * swift::misc::Optional< T >::operator-> ( )
inline

Indirection operator, returns pointer to contained value, undefined if there is no value contained.

Definition at line 118 of file optional.h.

◆ operator->() [2/2]

template<typename T>
const T * swift::misc::Optional< T >::operator-> ( ) const
inline

Indirection operator, returns pointer to contained value, undefined if there is no value contained.

Definition at line 121 of file optional.h.

◆ operator=() [1/3]

template<typename T>
Optional & swift::misc::Optional< T >::operator= ( const Optional< T > & other)
inlinenoexcept

Copy assignment.

Definition at line 66 of file optional.h.

◆ operator=() [2/3]

template<typename T>
Optional & swift::misc::Optional< T >::operator= ( Optional< T > && other)
inlinenoexcept

Move assignment.

Definition at line 78 of file optional.h.

◆ operator=() [3/3]

template<typename T>
Optional & swift::misc::Optional< T >::operator= ( std::nullptr_t )
inlinenoexcept

Assign a nullptr.

Definition at line 59 of file optional.h.

◆ reset()

template<typename T>
void swift::misc::Optional< T >::reset ( )
inlinenoexcept

If object is valid, destroy to make it invalid.

Definition at line 102 of file optional.h.


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