Opt< const T & > Class Template Reference

#include <optional.h>

Detailed Description

template<typename T>
class maxon::Opt< const T & >

Specialization to store const lvalue references, which only uses a single pointer internally. This can be used to treat pointers that may be null as optional references for more descriptive interfaces.

Public Types

using ValueType = const T &
 
template<typename SUPER >
using ResultFunctions = maxon::details::ResultOptFunctions< SUPER >
 

Public Member Functions

 Opt ()
 
MAXON_IMPLICIT Opt (NO_VALUE_TYPE)
 
 Opt (const Opt &src)
 
Optoperator= (const Opt &src)
 
MAXON_IMPLICIT Opt (const T &value)
 
MAXON_IMPLICIT Opt (const T *valuePtr)
 
Bool HasValue () const
 
Bool operator== (std::nullptr_t) const
 
Bool operator!= (std::nullptr_t) const
 
 operator Bool () const
 
Result< const T & > GetValue () const
 
const T & GetValueOr (const T &defaultValue) const
 
GetValueOr (T &&defaultValue) const
 
const T & GetValueOrDefault () const
 
MAXON_ATTRIBUTE_FORCE_INLINE const T & GetValueOrNull () const
 
const T * operator-> () const
 
const T & operator* () const
 
const T * ToPointer () const
 
template<typename TT , typename = typename std::enable_if<std::is_same<const TT, const T>::value || std::is_base_of<TT, T>::value>::type>
 operator const TT * () const
 
SFINAEHelper< String, T >::type ToString (const FormatStatement *format=nullptr) const
 
HashInt GetHashCode () const
 

Private Member Functions

MAXON_ATTRIBUTE_FORCE_INLINE void CheckValue () const
 

Private Attributes

const T * _dataPtr
 

Member Typedef Documentation

◆ ValueType

using ValueType = const T&

◆ ResultFunctions

Constructor & Destructor Documentation

◆ Opt() [1/5]

Opt ( )

Default constructor. Creates an Opt with no value.

◆ Opt() [2/5]

Explicit construction with NO_VALUE. Has the same effect as the default constructor.

◆ Opt() [3/5]

Opt ( const Opt< const T & > &  src)

Copy constructor.

◆ Opt() [4/5]

MAXON_IMPLICIT Opt ( const T &  value)

Constructs from const reference.

◆ Opt() [5/5]

MAXON_IMPLICIT Opt ( const T *  valuePtr)

Constructs from raw pointer.

Member Function Documentation

◆ operator=()

Opt& operator= ( const Opt< const T & > &  src)

Copy assignment.

◆ HasValue()

Bool HasValue ( ) const

Returns true if this object contains a value.

◆ operator==()

Bool operator== ( std::nullptr_t  ) const

◆ operator!=()

Bool operator!= ( std::nullptr_t  ) const

◆ operator Bool()

operator Bool ( ) const
explicit

◆ GetValue()

Result<const T&> GetValue ( ) const

Returns the contained value, or IllegalState error if object contained no value.

◆ GetValueOr() [1/2]

const T& GetValueOr ( const T &  defaultValue) const

Returns the contained value, or a default value if object contained no value.

◆ GetValueOr() [2/2]

T GetValueOr ( T &&  defaultValue) const

Returns the contained value, or a default value if object contained no value.

◆ GetValueOrDefault()

const T& GetValueOrDefault ( ) const

Returns the contained value, or a default value if object contained no value.

◆ GetValueOrNull()

MAXON_ATTRIBUTE_FORCE_INLINE const T& GetValueOrNull ( ) const

◆ operator->()

const T* operator-> ( ) const

Returns a pointer to the contained value. Results in undefined behavior if object contained no value.

◆ operator*()

const T& operator* ( ) const

Returns a reference to the contained value. Results in undefined behavior if object contained no value.

◆ ToPointer()

const T* ToPointer ( ) const

◆ operator const TT *()

operator const TT * ( ) const

Converts the optional reference to a raw pointer. This is supported for interoperability with legacy code.

◆ ToString()

SFINAEHelper<String, T>::type ToString ( const FormatStatement format = nullptr) const

Returns a formated string representation of this optional value.

◆ GetHashCode()

HashInt GetHashCode ( ) const

◆ CheckValue()

MAXON_ATTRIBUTE_FORCE_INLINE void CheckValue ( ) const
private

Member Data Documentation

◆ _dataPtr

const T* _dataPtr
private