SHOGUN  4.1.0
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
所有成员列表 | Public 成员函数 | 友元
Maybe< T > 模板类 参考

详细描述

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

参见
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,

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

To provide default values,

参见
value_or is used:
int value = unreliable.value_or(9);

在文件 maybe.h86 行定义.

Public 成员函数

 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
 

友元

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

构造及析构函数说明

Maybe ( const Nothing nothing)

Creates an instance from nothing resulting in absent value.

参数
nothinginstance of nothing

在文件 maybe.h94 行定义.

Maybe ( const Maybe< T > &  other)

Copy constructor.

参数
otherother instance of Maybe for the same type

在文件 maybe.h103 行定义.

成员函数说明

bool is_absent ( ) const

Returns true if value is absent, false otherwise.

Doesn't throw any exception.

在文件 maybe.h143 行定义.

bool is_present ( ) const

Returns true if value is present, false otherwise.

Doesn't throw any exception.

在文件 maybe.h152 行定义.

operator bool ( ) const

Evaluates to true when object is present, false otherwise.

Equivalent to

参见
is_present()

在文件 maybe.h113 行定义.

T& value ( )

Returns value if it is present, fails otherwise.

异常
ShogunExceptionif retrieved value is absent

在文件 maybe.h122 行定义.

T& value_or ( T &  v)

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

Doesn't throw any exception.

在文件 maybe.h131 行定义.

友元及相关函数文档

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

该类的文档由以下文件生成:

SHOGUN 机器学习工具包 - 项目文档