|
| constexpr | optional (none_t n=none) noexcept |
| | 从空值构造
|
| MSTL_CONSTEXPR20 optional & | operator= (none_t n) noexcept |
| | 空值赋值运算符
|
| template<typename U, enable_if_t< is_valid_optional< U >::value &&!is_same_v< remove_cvref_t< U >, optional > &&is_constructible_v< T, U > &&is_convertible_v< U, T >, int > = 0> |
| constexpr | optional (U &&value) noexcept(is_nothrow_constructible_v< T, U >) |
| | 从值隐式转换构造
|
| template<typename U, enable_if_t< is_valid_optional< U >::value &&!is_same_v< remove_cvref_t< U >, optional > &&is_constructible_v< T, U > &&!is_convertible_v< U, T >, int > = 0> |
| constexpr | optional (U &&value) noexcept(is_nothrow_constructible_v< T, U >) |
| | 从值显式转换构造
|
| template<typename U = T, enable_if_t<!is_same_v< remove_cvref_t< U >, optional > &&negation_v< conjunction< is_scalar< T >, is_same< T, decay_t< U > > > > &&is_constructible_v< T, U > &&is_assignable_v< T &, U >, int > = 0> |
| MSTL_CONSTEXPR20 optional & | operator= (U &&value) noexcept(is_nothrow_constructible_v< T, U > &&is_nothrow_assignable_v< T &, U >) |
| | 从值赋值
|
| template<typename U, enable_if_t<!is_same_v< T, U > &&is_constructible_v< T, const U & > &&is_convertible_v< const U &, T > &&convertible_from_optional< U >::value, int > = 0> |
| constexpr | optional (const optional< U > &other) noexcept(is_nothrow_constructible_v< T, const U & >) |
| | 从可选值隐式转换复制构造
|
| template<typename U, enable_if_t<!is_same_v< T, U > &&is_constructible_v< T, const U & > &&!is_convertible_v< const U &, T > &&convertible_from_optional< U >::value, int > = 0> |
| constexpr | optional (const optional< U > &other) noexcept(is_nothrow_constructible_v< T, const U & >) |
| | 从可选值显式转换复制构造
|
| template<typename U = T, enable_if_t<!is_same_v< remove_cvref_t< U >, optional > &&is_constructible_v< T, const U & > &&is_assignable_v< T &, const U & > &&!convertible_from_optional< U >::value &&!assignable_from_optional< U >::value, int > = 0> |
| MSTL_CONSTEXPR20 optional & | operator= (const optional< U > &other) noexcept(is_nothrow_constructible_v< T, const U & > &&is_nothrow_assignable_v< T &, const U & >) |
| | 从可选值复制赋值
|
| | optional (const optional &other) |
| | 复制构造函数
|
| optional & | operator= (const optional &other) |
| | 复制赋值运算符
|
| template<typename U, enable_if_t<!is_same_v< T, U > &&is_constructible_v< T, U > &&is_convertible_v< U, T > &&convertible_from_optional< U >::value, int > = 0> |
| constexpr | optional (optional< U > &&other) noexcept(is_nothrow_constructible_v< T, U >) |
| | 从可选值隐式转换移动构造
|
| template<typename U, enable_if_t<!is_same_v< T, U > &&is_constructible_v< T, U > &&!is_convertible_v< U, T > &&convertible_from_optional< U >::value, int > = 0> |
| constexpr | optional (optional< U > &&other) noexcept(is_nothrow_constructible_v< T, U >) |
| | 从可选值显式转换移动构造
|
| template<typename U = T, enable_if_t<!is_same_v< remove_cvref_t< U >, optional > &&is_constructible_v< T, U > &&is_assignable_v< T &, U > &&!convertible_from_optional< U >::value &&!assignable_from_optional< U >::value, int > = 0> |
| MSTL_CONSTEXPR20 optional & | operator= (optional< U > &&other) noexcept(is_nothrow_constructible_v< T, U > &&is_nothrow_assignable_v< T &, U >) |
| | 从可选值移动赋值
|
| | optional (optional &&other) noexcept |
| | 移动构造函数
|
| optional & | operator= (optional &&other) noexcept |
| | 移动赋值运算符
|
| template<typename U, enable_if_t< is_constructible_v< T, U & >, int > = 0> |
| constexpr | optional (const optional< U & > &other) |
| | 从引用可选值赋值
|
| template<typename U, enable_if_t< is_assignable_v< T &, U & >, int > = 0> |
| MSTL_CONSTEXPR20 optional & | operator= (const optional< U & > &other) |
| | 从引用可选值赋值
|
| template<typename ... Types, enable_if_t< is_constructible_v< T, Types... >, int > = 0> |
| constexpr | optional (inplace_construct_tag, Types &&... args) noexcept(is_nothrow_constructible_v< T, Types... >) |
| | 原位构造
|
| template<typename U, typename ... Types, enable_if_t< is_constructible_v< T, std::initializer_list< U > &, Types... >, int > = 0> |
| constexpr | optional (inplace_construct_tag, std::initializer_list< U > ilist, Types &&...args) noexcept(is_nothrow_constructible_v< T, std::initializer_list< U > &, Types... >) |
| | 使用初始化列表原位构造
|
|
MSTL_CONSTEXPR20 | ~optional () noexcept |
| | 析构函数
|
| template<typename... Types, enable_if_t< is_constructible_v< T, Types... >, int > = 0> |
| MSTL_CONSTEXPR20 void | emplace (Types &&... args) noexcept(is_nothrow_constructible_v< T, Types... >) |
| | 原位构造值
|
| template<typename U, typename... Types, enable_if_t< is_constructible_v< T, std::initializer_list< U > &, Types... >, int > = 0> |
| MSTL_CONSTEXPR20 void | emplace (std::initializer_list< U > ilist, Types &&... args) noexcept(is_nothrow_constructible_v< T, std::initializer_list< U > &, Types... >) |
| | 使用初始化列表原位构造值
|
|
MSTL_CONSTEXPR20 void | reset () noexcept |
| | 重置可选值为空
|
| MSTL_NODISCARD constexpr bool | has_value () const noexcept |
| | 检查是否包含值
|
| constexpr | operator bool () const noexcept |
| | 转换为布尔值
|
| constexpr const_reference | value () const & |
| | 取出存储的值
|
| constexpr reference | value () & |
| | 取出存储的值
|
| constexpr const value_type && | value () const && |
| | 取出存储的值
|
| constexpr value_type && | value () && |
| | 取出存储的值
|
| constexpr value_type | value_or (value_type value) const &noexcept(is_nothrow_copy_constructible_v< value_type >) |
| | 取出存储的值的拷贝值
|
| constexpr value_type | value_or (value_type value) &&noexcept(is_nothrow_move_constructible_v< value_type >) |
| | 取出存储的值的移出值
|
| template<typename F, enable_if_t< is_invocable_v< F > &&is_copy_constructible_v< T >, int > = 0> |
| constexpr optional | or_else (F &&f) const & |
| | 常量左值否则操作
|
| template<typename F, enable_if_t< is_invocable_v< F > &&is_move_constructible_v< T >, int > = 0> |
| constexpr optional | or_else (F &&f) && |
| | 右值否则操作
|
| template<typename F> |
| constexpr decltype(auto) | and_then (F &&f) const & |
| | 常量左值然后操作
|
| template<typename F> |
| constexpr decltype(auto) | and_then (F &&f) & |
| | 左值然后操作
|
| template<typename F> |
| constexpr decltype(auto) | and_then (F &&f) const && |
| | 常量右值然后操作
|
| template<typename F> |
| constexpr decltype(auto) | and_then (F &&f) && |
| | 右值然后操作
|
| template<typename F> |
| constexpr auto | transform (F &&f) const &-> optional< remove_cvref_t< decltype(f(*get_ptr()))> > |
| | 常量左值转换操作
|
| template<typename F> |
| constexpr auto | transform (F &&f) &-> optional< remove_cvref_t< decltype(f(*get_ptr()))> > |
| | 左值转换操作
|
| template<typename F> |
| constexpr auto | transform (F &&f) const &&-> optional< remove_cvref_t< decltype(f(_MSTL move(*get_ptr())))> > |
| | 右值转换操作
|
| template<typename F> |
| constexpr auto | transform (F &&f) &&-> optional< remove_cvref_t< decltype(f(_MSTL move(*get_ptr())))> > |
| | 常量右值转换操作
|
| constexpr const_pointer | operator-> () const noexcept |
| | 常量箭头运算符
|
| constexpr pointer | operator-> () noexcept |
| | 箭头运算符
|
| constexpr const_reference | operator* () const &noexcept |
| | 常量左值解引用运算符
|
| constexpr reference | operator* () &noexcept |
| | 左值解引用运算符
|
| constexpr const value_type && | operator* () const &&noexcept |
| | 常量右值解引用运算符
|
| constexpr value_type && | operator* () &&noexcept |
| | 右值解引用运算符
|
| constexpr bool | operator== (const optional &rhs) const noexcept |
| | 等于比较运算符
|
| constexpr bool | operator< (const optional &rhs) const noexcept |
| | 小于比较运算符
|
| constexpr size_t | to_hash () const noexcept |
| | 计算哈希值
|
| MSTL_CONSTEXPR20 void | swap (optional &other) noexcept(is_nothrow_move_constructible_v< T > &&is_nothrow_swappable_v< T >) |
| | 交换两个可选值
|
template<typename T>
class optional< T >
可选值类
- 模板参数
-
表示一个可能包含值也可能为空的对象。类似于指针,但拥有值语义。
在文件 optional.hpp 第 50 行定义.