Support Class Library
A set of tools providing classes and utility
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Friends | List of all members
scl::utils::Optional< T > Class Template Reference

A class that allows the use of optional types (might be there) More...

#include "Optional.h"

Public Types

using value_type = scl::tools::meta ::remove_cv_ref_t< T >
 

Public Member Functions

 Optional ()
 Default construct (no value) More...
 
bool hasValue () const
 Determines whether or not this Optional<T> is empty. More...
 
const value_typeget () const
 Retrieves the value stored in this Optional<T> More...
 
 Optional (const value_type &value)
 Creates a non empty optional with the given value (copy) More...
 
Optionaloperator= (const value_type &value)
 Assign a value to this optional. More...
 
 Optional (const Optional &o)
 Copy constructor. More...
 
Optionaloperator= (const Optional &rhs)
 Copy assignment operator. More...
 
 operator const value_type & () const
 Automatic conversion operator. More...
 
 Optional (Optional &&rhs)
 Move constructor. More...
 
Optionaloperator= (Optional &&rhs) noexcept
 Move assignment operator. More...
 
 Optional (None _)
 Instantiate an optional via an instance of None. More...
 
Optionaloperator= (None _)
 Assign from None. More...
 
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same< scl::tools::meta ::decay_t<U>, scl::tools::meta ::decay_t<T>>() && ! scl::tools::meta ::is_same< scl::tools::meta ::decay_t<U>, None>() && ! scl::tools::meta ::is_same< scl::tools::meta ::decay_t<U>, Optional>() >>
 Optional (const U &value)
 Implicit conversion copy constructor. More...
 
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same< scl::tools::meta ::decay_t<U>, scl::tools::meta ::decay_t<T>>() && ! scl::tools::meta ::is_same< scl::tools::meta ::decay_t<U>, None>() && ! scl::tools::meta ::is_same< scl::tools::meta ::decay_t<U>, Optional>() >>
Optionaloperator= (const U &value)
 Implicit conversion copy assignment. More...
 
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same< scl::tools::meta ::decay_t<U>, scl::tools::meta ::decay_t<T>>() && ! scl::tools::meta ::is_same< scl::tools::meta ::decay_t<U>, None>() && ! scl::tools::meta ::is_same< scl::tools::meta ::decay_t<U>, Optional>() >>
 Optional (U &&value)
 Implicit conversion move constructor. More...
 
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same< scl::tools::meta ::decay_t<U>, scl::tools::meta ::decay_t<T>>() && ! scl::tools::meta ::is_same< scl::tools::meta ::decay_t<U>, None>() && ! scl::tools::meta ::is_same< scl::tools::meta ::decay_t<U>, Optional>() >>
Optionaloperator= (U &&value)
 Implicit conversion move assignment. More...
 
const value_typevalue () const
 A semantic alias for Optional<T>::get. More...
 
const value_type *const ptr () const
 Get an immutable pointer to the contained value. More...
 
 operator bool () const
 Automatic bool conversion. More...
 
const value_typeoperator* () const
 Access to the value. More...
 
const value_type *const operator-> () const
 Get an immutable pointer to the stored value. More...
 
const value_typeorElse (const value_type &defaultValue) const
 Retrieves the value if there's one or return the default value provided. More...
 
template<class F >
const OptionaldoIfPresent (F &&f) const
 Calls a function if the value is present. More...
 
template<class F >
const OptionalifSome (F &&f) const
 Alias for scl::utils::Optional::doIfPresent. More...
 
template<class F >
const OptionaldoIfEmpty (F &&f) const
 Calls a function if there is no value. More...
 
template<class F >
const OptionalifNone (F &&f) const
 Alias for scl::utils::Optional::doIfEmpty. More...
 
template<class E >
const value_typeorThrow (const E &e) const
 Tries to retrieve the value, throws the given exception if there's none. More...
 
template<class U , class F >
Optional< U > map (F &&mapper) const
 Maps this Optional<T> to an Optional<U> via the provided mapper function (T -> U) More...
 
template<class U , class F >
Optional< U > mapTo (F &&mapper) const
 Alias for Optional::map. More...
 
template<class F >
Optional< T > filter (F predicate) const
 Filters the value according to the given predicate. More...
 
template<class U , class F >
Optional< U > flatMap (F &&mapper) const
 Flat maps this optional to an optional of another type. More...
 
template<class U , class F >
Optional< U > flatMapTo (F &&mapper) const
 Alias for Optional::flatMap. More...
 
bool operator== (None) const
 
bool operator< (None) const
 
bool operator<= (None) const
 
bool operator> (None) const
 
bool operator>= (None) const
 
bool operator!= (None) const
 
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same<U, None>() && ! scl::tools::meta ::is_same<U, Optional>() && ! scl::tools::meta ::is_instance<scl::utils::Optional, U>() >>
bool operator== (const U &t) const
 
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same<U, None>() && ! scl::tools::meta ::is_same<U, Optional>() && ! scl::tools::meta ::is_instance<scl::utils::Optional, U>() >>
bool operator!= (const U &t) const
 
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same<U, None>() && ! scl::tools::meta ::is_same<U, Optional>() && ! scl::tools::meta ::is_instance<scl::utils::Optional, U>() >>
bool operator< (const U &t) const
 
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same<U, None>() && ! scl::tools::meta ::is_same<U, Optional>() && ! scl::tools::meta ::is_instance<scl::utils::Optional, U>() >>
bool operator<= (const U &t) const
 
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same<U, None>() && ! scl::tools::meta ::is_same<U, Optional>() && ! scl::tools::meta ::is_instance<scl::utils::Optional, U>() >>
bool operator> (const U &t) const
 
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same<U, None>() && ! scl::tools::meta ::is_same<U, Optional>() && ! scl::tools::meta ::is_instance<scl::utils::Optional, U>() >>
bool operator>= (const U &t) const
 
template<class U >
bool operator== (const Optional< U > &o) const
 
template<class U >
bool operator!= (const Optional< U > &o) const
 
template<class U >
bool operator< (const Optional< U > &o) const
 
template<class U >
bool operator<= (const Optional< U > &o) const
 
template<class U >
bool operator> (const Optional< U > &o) const
 
template<class U >
bool operator>= (const Optional< U > &o) const
 

Static Public Member Functions

static constexpr Optional fromPointer (const T *ptr)
 Construct an optional from a pointer. More...
 
static constexpr Optional fromPointer (std::nullptr_t)
 
template<class... Args>
static Optional inplace (Args &&... args)
 Construct an optional inplace. More...
 
static Optional ref (const value_type &ref)
 Construct an optional from a reference to an object. More...
 

Protected Attributes

RawStorage< T > payload
 A raw storage to hold an instance of the object. More...
 

Friends

bool operator== (None, const Optional &o)
 
bool operator< (None, const Optional &)
 
bool operator<= (None, const Optional &)
 
bool operator> (None, const Optional &)
 
bool operator>= (None, const Optional &o)
 
bool operator!= (None, const Optional &o)
 
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same<U, None>() && ! scl::tools::meta ::is_same<U, Optional>() && ! scl::tools::meta ::is_instance<scl::utils::Optional, U>() >>
bool operator== (const U &t, const Optional &o)
 
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same<U, None>() && ! scl::tools::meta ::is_same<U, Optional>() && ! scl::tools::meta ::is_instance<scl::utils::Optional, U>() >>
bool operator!= (const U &t, const Optional &o)
 
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same<U, None>() && ! scl::tools::meta ::is_same<U, Optional>() && ! scl::tools::meta ::is_instance<scl::utils::Optional, U>() >>
bool operator< (const U &t, const Optional &o)
 
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same<U, None>() && ! scl::tools::meta ::is_same<U, Optional>() && ! scl::tools::meta ::is_instance<scl::utils::Optional, U>() >>
bool operator<= (const U &t, const Optional &o)
 
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same<U, None>() && ! scl::tools::meta ::is_same<U, Optional>() && ! scl::tools::meta ::is_instance<scl::utils::Optional, U>() >>
bool operator> (const U &t, const Optional &o)
 
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same<U, None>() && ! scl::tools::meta ::is_same<U, Optional>() && ! scl::tools::meta ::is_instance<scl::utils::Optional, U>() >>
bool operator>= (const U &t, const Optional &o)
 

Detailed Description

template<class T>
class scl::utils::Optional< T >

A class that allows the use of optional types (might be there)

Template Parameters
Tbeing the value type that is optional
Warning
Optional defines move and/or copy semantics only if the underlying type does as well

Definition at line 65 of file Optional.h.

Member Typedef Documentation

◆ value_type

template<class T>
using scl::utils::Optional< T >::value_type = scl::tools::meta ::remove_cv_ref_t<T>

Definition at line 74 of file Optional.h.

Constructor & Destructor Documentation

◆ Optional() [1/7]

template<class T>
scl::utils::Optional< T >::Optional ( )
inline

Default construct (no value)

Definition at line 118 of file Optional.h.

◆ Optional() [2/7]

template<class T>
scl::utils::Optional< T >::Optional ( const value_type value)
inline

Creates a non empty optional with the given value (copy)

Parameters
valuebeing the value to assign from

Definition at line 145 of file Optional.h.

◆ Optional() [3/7]

template<class T>
scl::utils::Optional< T >::Optional ( const Optional< T > &  o)
inline

Copy constructor.

Parameters
obeing the Optional to copy from

Definition at line 163 of file Optional.h.

◆ Optional() [4/7]

template<class T>
scl::utils::Optional< T >::Optional ( Optional< T > &&  rhs)
inline

Move constructor.

Parameters
rhsbeing the Optional to construct from
Warning
moved-from Optional are in empty state (i.e. equivalent to one constructed from none)

Definition at line 194 of file Optional.h.

◆ Optional() [5/7]

template<class T>
scl::utils::Optional< T >::Optional ( None  _)
inline

Instantiate an optional via an instance of None.

Parameters
_being an instance of None

Definition at line 219 of file Optional.h.

◆ Optional() [6/7]

template<class T>
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same< scl::tools::meta ::decay_t<U>, scl::tools::meta ::decay_t<T>>() && ! scl::tools::meta ::is_same< scl::tools::meta ::decay_t<U>, None>() && ! scl::tools::meta ::is_same< scl::tools::meta ::decay_t<U>, Optional>() >>
scl::utils::Optional< T >::Optional ( const U &  value)
inline

Implicit conversion copy constructor.

Template Parameters
Ubeing the type to implicitly convert from
Parameters
valuebeing the value to construct from

Definition at line 243 of file Optional.h.

◆ Optional() [7/7]

template<class T>
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same< scl::tools::meta ::decay_t<U>, scl::tools::meta ::decay_t<T>>() && ! scl::tools::meta ::is_same< scl::tools::meta ::decay_t<U>, None>() && ! scl::tools::meta ::is_same< scl::tools::meta ::decay_t<U>, Optional>() >>
scl::utils::Optional< T >::Optional ( U &&  value)
inline

Implicit conversion move constructor.

Template Parameters
Ubeing the type to implicitly convert from
Parameters
valuebeing the value to construct from

Definition at line 265 of file Optional.h.

Member Function Documentation

◆ doIfEmpty()

template<class T>
template<class F >
const Optional& scl::utils::Optional< T >::doIfEmpty ( F &&  f) const
inline

Calls a function if there is no value.

Template Parameters
Fbeing the function's type
Parameters
fbeing the function to call
Returns
a reference to this optional (for chaining purposes)

Definition at line 355 of file Optional.h.

◆ doIfPresent()

template<class T>
template<class F >
const Optional& scl::utils::Optional< T >::doIfPresent ( F &&  f) const
inline

Calls a function if the value is present.

Template Parameters
Fbeing the function's type
Parameters
fbeing the function to call
Returns
a reference to this optional (for chaining purposes)

Definition at line 333 of file Optional.h.

◆ filter()

template<class T>
template<class F >
Optional<T> scl::utils::Optional< T >::filter ( predicate) const
inline

Filters the value according to the given predicate.

Template Parameters
Fbeing the type of predicate (auto deduction)
Parameters
predicatebeing the predicate used to determine whether or not it should keep the value
Returns
a new optional that might not contain the original value

Definition at line 414 of file Optional.h.

◆ flatMap()

template<class T>
template<class U , class F >
Optional<U> scl::utils::Optional< T >::flatMap ( F &&  mapper) const
inline

Flat maps this optional to an optional of another type.

Template Parameters
Ubeing the value type of the mapped optional
Fbeing the mapper's type
Parameters
mapperbeing the mapper function
Returns
the mapped optional

Definition at line 431 of file Optional.h.

◆ flatMapTo()

template<class T>
template<class U , class F >
Optional<U> scl::utils::Optional< T >::flatMapTo ( F &&  mapper) const
inline

Alias for Optional::flatMap.

Definition at line 439 of file Optional.h.

◆ fromPointer() [1/2]

template<class T>
static constexpr Optional scl::utils::Optional< T >::fromPointer ( const T *  ptr)
inlinestatic

Construct an optional from a pointer.

Parameters
ptrbeing the pointer to construct from
Returns
an empty optional if ptr is null, an initialized pointer otherwise

Definition at line 82 of file Optional.h.

◆ fromPointer() [2/2]

template<class T>
static constexpr Optional scl::utils::Optional< T >::fromPointer ( std::nullptr_t  )
inlinestatic

Definition at line 86 of file Optional.h.

◆ get()

template<class T>
const value_type& scl::utils::Optional< T >::get ( ) const
inline

Retrieves the value stored in this Optional<T>

Returns
a const& to the value stored
Exceptions
scl::exceptions::EmptyOptionalAccessif there's no value

Definition at line 134 of file Optional.h.

◆ hasValue()

template<class T>
bool scl::utils::Optional< T >::hasValue ( ) const
inline

Determines whether or not this Optional<T> is empty.

Returns
TRUE if there's a value, FALSE otherwise

Definition at line 125 of file Optional.h.

◆ ifNone()

template<class T>
template<class F >
const Optional& scl::utils::Optional< T >::ifNone ( F &&  f) const
inline

Alias for scl::utils::Optional::doIfEmpty.

Definition at line 366 of file Optional.h.

◆ ifSome()

template<class T>
template<class F >
const Optional& scl::utils::Optional< T >::ifSome ( F &&  f) const
inline

Alias for scl::utils::Optional::doIfPresent.

Definition at line 344 of file Optional.h.

◆ inplace()

template<class T>
template<class... Args>
static Optional scl::utils::Optional< T >::inplace ( Args &&...  args)
inlinestatic

Construct an optional inplace.

Template Parameters
Argsbeing the types of the arguments for the constructor
Parameters
argsbeing the arguments for the constructor
Returns
an initialized optional

Definition at line 97 of file Optional.h.

◆ map()

template<class T>
template<class U , class F >
Optional<U> scl::utils::Optional< T >::map ( F &&  mapper) const
inline

Maps this Optional<T> to an Optional<U> via the provided mapper function (T -> U)

Template Parameters
Ubeing the value type for the mapped optional
Fbeing the type of the mapper function (auto deduction)
Parameters
mapperbeing the mapper function to use to map values
Returns
an Optional<U>

Definition at line 392 of file Optional.h.

◆ mapTo()

template<class T>
template<class U , class F >
Optional<U> scl::utils::Optional< T >::mapTo ( F &&  mapper) const
inline

Alias for Optional::map.

Definition at line 405 of file Optional.h.

◆ operator bool()

template<class T>
scl::utils::Optional< T >::operator bool ( ) const
inline

Automatic bool conversion.

Returns
TRUE if there's a value, FALSE otherwise

Definition at line 301 of file Optional.h.

◆ operator const value_type &()

template<class T>
scl::utils::Optional< T >::operator const value_type & ( ) const
inline

Automatic conversion operator.

Returns
a const reference to the underlying value
Exceptions
scl::exceptions::EmptyOptionalAccessif there's no value

Definition at line 185 of file Optional.h.

◆ operator!=() [1/3]

template<class T>
bool scl::utils::Optional< T >::operator!= ( None  ) const
inline

Definition at line 459 of file Optional.h.

◆ operator!=() [2/3]

template<class T>
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same<U, None>() && ! scl::tools::meta ::is_same<U, Optional>() && ! scl::tools::meta ::is_instance<scl::utils::Optional, U>() >>
bool scl::utils::Optional< T >::operator!= ( const U &  t) const
inline

Definition at line 470 of file Optional.h.

◆ operator!=() [3/3]

template<class T>
template<class U >
bool scl::utils::Optional< T >::operator!= ( const Optional< U > &  o) const
inline

Definition at line 504 of file Optional.h.

◆ operator*()

template<class T>
const value_type& scl::utils::Optional< T >::operator* ( ) const
inline

Access to the value.

Returns
a const& to the value stored
Exceptions
scl::exceptions::EmptyOptionalAccessif there's no value

Definition at line 308 of file Optional.h.

◆ operator->()

template<class T>
const value_type* const scl::utils::Optional< T >::operator-> ( ) const
inline

Get an immutable pointer to the stored value.

Returns
a realConst T* to the value stored
Exceptions
scl::exceptions::EmptyOptionalAccessif there's no value

Definition at line 315 of file Optional.h.

◆ operator<() [1/3]

template<class T>
bool scl::utils::Optional< T >::operator< ( None  ) const
inline

Definition at line 447 of file Optional.h.

◆ operator<() [2/3]

template<class T>
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same<U, None>() && ! scl::tools::meta ::is_same<U, Optional>() && ! scl::tools::meta ::is_instance<scl::utils::Optional, U>() >>
bool scl::utils::Optional< T >::operator< ( const U &  t) const
inline

Definition at line 472 of file Optional.h.

◆ operator<() [3/3]

template<class T>
template<class U >
bool scl::utils::Optional< T >::operator< ( const Optional< U > &  o) const
inline

Definition at line 507 of file Optional.h.

◆ operator<=() [1/3]

template<class T>
bool scl::utils::Optional< T >::operator<= ( None  ) const
inline

Definition at line 450 of file Optional.h.

◆ operator<=() [2/3]

template<class T>
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same<U, None>() && ! scl::tools::meta ::is_same<U, Optional>() && ! scl::tools::meta ::is_instance<scl::utils::Optional, U>() >>
bool scl::utils::Optional< T >::operator<= ( const U &  t) const
inline

Definition at line 474 of file Optional.h.

◆ operator<=() [3/3]

template<class T>
template<class U >
bool scl::utils::Optional< T >::operator<= ( const Optional< U > &  o) const
inline

Definition at line 515 of file Optional.h.

◆ operator=() [1/6]

template<class T>
Optional& scl::utils::Optional< T >::operator= ( const value_type value)
inline

Assign a value to this optional.

Parameters
valuebeing the value taken by the optional
Returns
a reference to this Optional

Definition at line 154 of file Optional.h.

◆ operator=() [2/6]

template<class T>
Optional& scl::utils::Optional< T >::operator= ( const Optional< T > &  rhs)
inline

Copy assignment operator.

Parameters
rhsbeing the Optional to assign from
Returns
a reference to this Optional<T>

Definition at line 173 of file Optional.h.

◆ operator=() [3/6]

template<class T>
Optional& scl::utils::Optional< T >::operator= ( Optional< T > &&  rhs)
inlinenoexcept

Move assignment operator.

Parameters
rhsbeing the Optional to assign from
Returns
a reference to this Optional<T>
Warning
moved-from Optional are in empty state (i.e. equivalent to one constructed from none)

Definition at line 207 of file Optional.h.

◆ operator=() [4/6]

template<class T>
Optional& scl::utils::Optional< T >::operator= ( None  _)
inline

Assign from None.

Parameters
_being an instance of None
Returns
a reference to this Optional

Definition at line 227 of file Optional.h.

◆ operator=() [5/6]

template<class T>
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same< scl::tools::meta ::decay_t<U>, scl::tools::meta ::decay_t<T>>() && ! scl::tools::meta ::is_same< scl::tools::meta ::decay_t<U>, None>() && ! scl::tools::meta ::is_same< scl::tools::meta ::decay_t<U>, Optional>() >>
Optional& scl::utils::Optional< T >::operator= ( const U &  value)
inline

Implicit conversion copy assignment.

Template Parameters
Ubeing the type to implicitly convert from
Parameters
valuebeing the value to assign from
Returns
a reference to this Optional

Definition at line 254 of file Optional.h.

◆ operator=() [6/6]

template<class T>
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same< scl::tools::meta ::decay_t<U>, scl::tools::meta ::decay_t<T>>() && ! scl::tools::meta ::is_same< scl::tools::meta ::decay_t<U>, None>() && ! scl::tools::meta ::is_same< scl::tools::meta ::decay_t<U>, Optional>() >>
Optional& scl::utils::Optional< T >::operator= ( U &&  value)
inline

Implicit conversion move assignment.

Template Parameters
Ubeing the type to implicitly convert from
Parameters
valuebeing the value to assign from
Returns
a reference to this Optional

Definition at line 276 of file Optional.h.

◆ operator==() [1/3]

template<class T>
bool scl::utils::Optional< T >::operator== ( None  ) const
inline

Definition at line 444 of file Optional.h.

◆ operator==() [2/3]

template<class T>
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same<U, None>() && ! scl::tools::meta ::is_same<U, Optional>() && ! scl::tools::meta ::is_instance<scl::utils::Optional, U>() >>
bool scl::utils::Optional< T >::operator== ( const U &  t) const
inline

Definition at line 468 of file Optional.h.

◆ operator==() [3/3]

template<class T>
template<class U >
bool scl::utils::Optional< T >::operator== ( const Optional< U > &  o) const
inline

Definition at line 496 of file Optional.h.

◆ operator>() [1/3]

template<class T>
bool scl::utils::Optional< T >::operator> ( None  ) const
inline

Definition at line 453 of file Optional.h.

◆ operator>() [2/3]

template<class T>
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same<U, None>() && ! scl::tools::meta ::is_same<U, Optional>() && ! scl::tools::meta ::is_instance<scl::utils::Optional, U>() >>
bool scl::utils::Optional< T >::operator> ( const U &  t) const
inline

Definition at line 476 of file Optional.h.

◆ operator>() [3/3]

template<class T>
template<class U >
bool scl::utils::Optional< T >::operator> ( const Optional< U > &  o) const
inline

Definition at line 518 of file Optional.h.

◆ operator>=() [1/3]

template<class T>
bool scl::utils::Optional< T >::operator>= ( None  ) const
inline

Definition at line 456 of file Optional.h.

◆ operator>=() [2/3]

template<class T>
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same<U, None>() && ! scl::tools::meta ::is_same<U, Optional>() && ! scl::tools::meta ::is_instance<scl::utils::Optional, U>() >>
bool scl::utils::Optional< T >::operator>= ( const U &  t) const
inline

Definition at line 478 of file Optional.h.

◆ operator>=() [3/3]

template<class T>
template<class U >
bool scl::utils::Optional< T >::operator>= ( const Optional< U > &  o) const
inline

Definition at line 521 of file Optional.h.

◆ orElse()

template<class T>
const value_type& scl::utils::Optional< T >::orElse ( const value_type defaultValue) const
inline

Retrieves the value if there's one or return the default value provided.

Parameters
defaultValuebeing the value to return if there's no values
Returns
a const reference to the stored value

Definition at line 322 of file Optional.h.

◆ orThrow()

template<class T>
template<class E >
const value_type& scl::utils::Optional< T >::orThrow ( const E &  e) const
inline

Tries to retrieve the value, throws the given exception if there's none.

Template Parameters
Ebeing the exception type
Parameters
ebeing the exception to throw if there's no value
Returns
a const& to the value

Definition at line 377 of file Optional.h.

◆ ptr()

template<class T>
const value_type* const scl::utils::Optional< T >::ptr ( ) const
inline

Get an immutable pointer to the contained value.

Returns
a realConst(T*) to the value
Exceptions
scl::exceptions::EmptyOptionalAccessif there's no value

Definition at line 295 of file Optional.h.

◆ ref()

template<class T>
static Optional scl::utils::Optional< T >::ref ( const value_type ref)
inlinestatic

Construct an optional from a reference to an object.

Parameters
refbeing the reference to construct from
Returns
an initialized optional

Definition at line 109 of file Optional.h.

◆ value()

template<class T>
const value_type& scl::utils::Optional< T >::value ( ) const
inline

A semantic alias for Optional<T>::get.

Returns
a const& to the stored value
Exceptions
scl::exceptions::EmptyOptionalAccessif there's no value

Definition at line 288 of file Optional.h.

Friends And Related Function Documentation

◆ operator!= [1/2]

template<class T>
bool operator!= ( None  ,
const Optional< T > &  o 
)
friend

Definition at line 460 of file Optional.h.

◆ operator!= [2/2]

template<class T>
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same<U, None>() && ! scl::tools::meta ::is_same<U, Optional>() && ! scl::tools::meta ::is_instance<scl::utils::Optional, U>() >>
bool operator!= ( const U &  t,
const Optional< T > &  o 
)
friend

Definition at line 483 of file Optional.h.

◆ operator< [1/2]

template<class T>
bool operator< ( None  ,
const Optional< T > &   
)
friend

Definition at line 448 of file Optional.h.

◆ operator< [2/2]

template<class T>
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same<U, None>() && ! scl::tools::meta ::is_same<U, Optional>() && ! scl::tools::meta ::is_instance<scl::utils::Optional, U>() >>
bool operator< ( const U &  t,
const Optional< T > &  o 
)
friend

Definition at line 485 of file Optional.h.

◆ operator<= [1/2]

template<class T>
bool operator<= ( None  ,
const Optional< T > &   
)
friend

Definition at line 451 of file Optional.h.

◆ operator<= [2/2]

template<class T>
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same<U, None>() && ! scl::tools::meta ::is_same<U, Optional>() && ! scl::tools::meta ::is_instance<scl::utils::Optional, U>() >>
bool operator<= ( const U &  t,
const Optional< T > &  o 
)
friend

Definition at line 487 of file Optional.h.

◆ operator== [1/2]

template<class T>
bool operator== ( None  ,
const Optional< T > &  o 
)
friend

Definition at line 445 of file Optional.h.

◆ operator== [2/2]

template<class T>
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same<U, None>() && ! scl::tools::meta ::is_same<U, Optional>() && ! scl::tools::meta ::is_instance<scl::utils::Optional, U>() >>
bool operator== ( const U &  t,
const Optional< T > &  o 
)
friend

Definition at line 481 of file Optional.h.

◆ operator> [1/2]

template<class T>
bool operator> ( None  ,
const Optional< T > &   
)
friend

Definition at line 454 of file Optional.h.

◆ operator> [2/2]

template<class T>
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same<U, None>() && ! scl::tools::meta ::is_same<U, Optional>() && ! scl::tools::meta ::is_instance<scl::utils::Optional, U>() >>
bool operator> ( const U &  t,
const Optional< T > &  o 
)
friend

Definition at line 489 of file Optional.h.

◆ operator>= [1/2]

template<class T>
bool operator>= ( None  ,
const Optional< T > &  o 
)
friend

Definition at line 457 of file Optional.h.

◆ operator>= [2/2]

template<class T>
template<class U , class = scl::tools::meta ::enable_if_t< ! scl::tools::meta ::is_same<U, None>() && ! scl::tools::meta ::is_same<U, Optional>() && ! scl::tools::meta ::is_instance<scl::utils::Optional, U>() >>
bool operator>= ( const U &  t,
const Optional< T > &  o 
)
friend

Definition at line 491 of file Optional.h.

Member Data Documentation

◆ payload

template<class T>
scl::utils::Optional< T >::payload
protected

A raw storage to hold an instance of the object.

Definition at line 71 of file Optional.h.


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