SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
List of all members | Public Member Functions | Friends
Maybe< T > Class Template Reference

Detailed Description

template<typename T>
class shogun::Maybe< T >

Holder that represents an object that can be either present or absent. Quite simllar to std::optional introduced in C++14, but provides a way to pass the reason of absence (e.g. "incorrect parameter").

Essentially, instances are created via

See also
Just or
Nothing
Maybe<int> absent_value = Nothing();
Maybe<int> present_value = Just(3);

To check whether value is present, regular implicit cast to bool is used:

if (maybe_value)
{
// value exists!
}
else
{
// value doesn't exist!
}

To obtain value,

See also
value is used:
// may throw an exception
int value = unreliable.value();

To provide default values,

See also
value_or is used:
int value = unreliable.value_or(9);

Definition at line 86 of file maybe.h.

Public Member Functions

 Maybe (const Nothing &nothing)
 
 Maybe (const Maybe< T > &other)
 
 operator bool () const
 
T & value ()
 
T & value_or (T &v)
 
bool is_absent () const
 
bool is_present () const
 

Friends

template<typename Q >
Maybe< Q > Just (const Q &value)
 

Constructor & Destructor Documentation

Maybe ( const Nothing nothing)

Creates an instance from nothing resulting in absent value.

Parameters
nothinginstance of nothing

Definition at line 94 of file maybe.h.

Maybe ( const Maybe< T > &  other)

Copy constructor.

Parameters
otherother instance of Maybe for the same type

Definition at line 103 of file maybe.h.

Member Function Documentation

bool is_absent ( ) const

Returns true if value is absent, false otherwise.

Doesn't throw any exception.

Definition at line 143 of file maybe.h.

bool is_present ( ) const

Returns true if value is present, false otherwise.

Doesn't throw any exception.

Definition at line 152 of file maybe.h.

operator bool ( ) const

Evaluates to true when object is present, false otherwise.

Equivalent to

See also
is_present()

Definition at line 113 of file maybe.h.

T& value ( )

Returns value if it is present, fails otherwise.

Exceptions
ShogunExceptionif retrieved value is absent

Definition at line 122 of file maybe.h.

T& value_or ( T &  v)

Returns value if it is present, or the provided default value.

Doesn't throw any exception.

Definition at line 131 of file maybe.h.

Friends And Related Function Documentation

Maybe<Q> Just ( const Q &  value)
friend

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

SHOGUN Machine Learning Toolbox - Documentation