Support Class Library
A set of tools providing classes and utility
|
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_type & | get () 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... | |
Optional & | operator= (const value_type &value) |
Assign a value to this optional. More... | |
Optional (const Optional &o) | |
Copy constructor. More... | |
Optional & | operator= (const Optional &rhs) |
Copy assignment operator. More... | |
operator const value_type & () const | |
Automatic conversion operator. More... | |
Optional (Optional &&rhs) | |
Move constructor. More... | |
Optional & | operator= (Optional &&rhs) noexcept |
Move assignment operator. More... | |
Optional (None _) | |
Instantiate an optional via an instance of None. More... | |
Optional & | operator= (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>() >> | |
Optional & | operator= (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>() >> | |
Optional & | operator= (U &&value) |
Implicit conversion move assignment. More... | |
const value_type & | value () 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_type & | operator* () const |
Access to the value. More... | |
const value_type *const | operator-> () const |
Get an immutable pointer to the stored value. More... | |
const value_type & | orElse (const value_type &defaultValue) const |
Retrieves the value if there's one or return the default value provided. More... | |
template<class F > | |
const Optional & | doIfPresent (F &&f) const |
Calls a function if the value is present. More... | |
template<class F > | |
const Optional & | ifSome (F &&f) const |
Alias for scl::utils::Optional::doIfPresent. More... | |
template<class F > | |
const Optional & | doIfEmpty (F &&f) const |
Calls a function if there is no value. More... | |
template<class F > | |
const Optional & | ifNone (F &&f) const |
Alias for scl::utils::Optional::doIfEmpty. More... | |
template<class E > | |
const value_type & | orThrow (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) |
A class that allows the use of optional types (might be there)
T | being the value type that is optional |
Definition at line 65 of file Optional.h.
using scl::utils::Optional< T >::value_type = scl::tools::meta ::remove_cv_ref_t<T> |
Definition at line 74 of file Optional.h.
|
inline |
Default construct (no value)
Definition at line 118 of file Optional.h.
|
inline |
Creates a non empty optional with the given value (copy)
value | being the value to assign from |
Definition at line 145 of file Optional.h.
|
inline |
Copy constructor.
o | being the Optional to copy from |
Definition at line 163 of file Optional.h.
|
inline |
Move constructor.
rhs | being the Optional to construct from |
Definition at line 194 of file Optional.h.
|
inline |
Instantiate an optional via an instance of None.
_ | being an instance of None |
Definition at line 219 of file Optional.h.
|
inline |
Implicit conversion copy constructor.
U | being the type to implicitly convert from |
value | being the value to construct from |
Definition at line 243 of file Optional.h.
|
inline |
Implicit conversion move constructor.
U | being the type to implicitly convert from |
value | being the value to construct from |
Definition at line 265 of file Optional.h.
|
inline |
Calls a function if there is no value.
F | being the function's type |
f | being the function to call |
Definition at line 355 of file Optional.h.
|
inline |
Calls a function if the value is present.
F | being the function's type |
f | being the function to call |
Definition at line 333 of file Optional.h.
|
inline |
Filters the value according to the given predicate.
F | being the type of predicate (auto deduction) |
predicate | being the predicate used to determine whether or not it should keep the value |
Definition at line 414 of file Optional.h.
|
inline |
Flat maps this optional to an optional of another type.
U | being the value type of the mapped optional |
F | being the mapper's type |
mapper | being the mapper function |
Definition at line 431 of file Optional.h.
|
inline |
Alias for Optional::flatMap.
Definition at line 439 of file Optional.h.
|
inlinestatic |
Construct an optional from a pointer.
ptr | being the pointer to construct from |
Definition at line 82 of file Optional.h.
|
inlinestatic |
Definition at line 86 of file Optional.h.
|
inline |
Retrieves the value stored in this Optional<T>
scl::exceptions::EmptyOptionalAccess | if there's no value |
Definition at line 134 of file Optional.h.
|
inline |
Determines whether or not this Optional<T> is empty.
Definition at line 125 of file Optional.h.
|
inline |
Alias for scl::utils::Optional::doIfEmpty.
Definition at line 366 of file Optional.h.
|
inline |
Alias for scl::utils::Optional::doIfPresent.
Definition at line 344 of file Optional.h.
|
inlinestatic |
Construct an optional inplace.
Args | being the types of the arguments for the constructor |
args | being the arguments for the constructor |
Definition at line 97 of file Optional.h.
|
inline |
Maps this Optional<T> to an Optional<U> via the provided mapper function (T -> U)
U | being the value type for the mapped optional |
F | being the type of the mapper function (auto deduction) |
mapper | being the mapper function to use to map values |
Definition at line 392 of file Optional.h.
|
inline |
Alias for Optional::map.
Definition at line 405 of file Optional.h.
|
inline |
Automatic bool conversion.
Definition at line 301 of file Optional.h.
|
inline |
Automatic conversion operator.
scl::exceptions::EmptyOptionalAccess | if there's no value |
Definition at line 185 of file Optional.h.
|
inline |
Definition at line 459 of file Optional.h.
|
inline |
Definition at line 470 of file Optional.h.
|
inline |
Definition at line 504 of file Optional.h.
|
inline |
Access to the value.
scl::exceptions::EmptyOptionalAccess | if there's no value |
Definition at line 308 of file Optional.h.
|
inline |
Get an immutable pointer to the stored value.
scl::exceptions::EmptyOptionalAccess | if there's no value |
Definition at line 315 of file Optional.h.
|
inline |
Definition at line 447 of file Optional.h.
|
inline |
Definition at line 472 of file Optional.h.
|
inline |
Definition at line 507 of file Optional.h.
|
inline |
Definition at line 450 of file Optional.h.
|
inline |
Definition at line 474 of file Optional.h.
|
inline |
Definition at line 515 of file Optional.h.
|
inline |
Assign a value to this optional.
value | being the value taken by the optional |
Definition at line 154 of file Optional.h.
|
inline |
Copy assignment operator.
rhs | being the Optional to assign from |
Definition at line 173 of file Optional.h.
|
inlinenoexcept |
Move assignment operator.
rhs | being the Optional to assign from |
Definition at line 207 of file Optional.h.
|
inline |
Assign from None.
_ | being an instance of None |
Definition at line 227 of file Optional.h.
|
inline |
Implicit conversion copy assignment.
U | being the type to implicitly convert from |
value | being the value to assign from |
Definition at line 254 of file Optional.h.
|
inline |
Implicit conversion move assignment.
U | being the type to implicitly convert from |
value | being the value to assign from |
Definition at line 276 of file Optional.h.
|
inline |
Definition at line 444 of file Optional.h.
|
inline |
Definition at line 468 of file Optional.h.
|
inline |
Definition at line 496 of file Optional.h.
|
inline |
Definition at line 453 of file Optional.h.
|
inline |
Definition at line 476 of file Optional.h.
|
inline |
Definition at line 518 of file Optional.h.
|
inline |
Definition at line 456 of file Optional.h.
|
inline |
Definition at line 478 of file Optional.h.
|
inline |
Definition at line 521 of file Optional.h.
|
inline |
Retrieves the value if there's one or return the default value provided.
defaultValue | being the value to return if there's no values |
Definition at line 322 of file Optional.h.
|
inline |
Tries to retrieve the value, throws the given exception if there's none.
E | being the exception type |
e | being the exception to throw if there's no value |
Definition at line 377 of file Optional.h.
|
inline |
Get an immutable pointer to the contained value.
scl::exceptions::EmptyOptionalAccess | if there's no value |
Definition at line 295 of file Optional.h.
|
inlinestatic |
Construct an optional from a reference to an object.
ref | being the reference to construct from |
Definition at line 109 of file Optional.h.
|
inline |
A semantic alias for Optional<T>::get.
scl::exceptions::EmptyOptionalAccess | if there's no value |
Definition at line 288 of file Optional.h.
Definition at line 460 of file Optional.h.
|
friend |
Definition at line 483 of file Optional.h.
Definition at line 448 of file Optional.h.
|
friend |
Definition at line 485 of file Optional.h.
Definition at line 451 of file Optional.h.
|
friend |
Definition at line 487 of file Optional.h.
Definition at line 445 of file Optional.h.
|
friend |
Definition at line 481 of file Optional.h.
Definition at line 454 of file Optional.h.
|
friend |
Definition at line 489 of file Optional.h.
Definition at line 457 of file Optional.h.
|
friend |
Definition at line 491 of file Optional.h.
|
protected |
A raw storage to hold an instance of the object.
Definition at line 71 of file Optional.h.