更新时间:2022-03-21 22:37:58
work = std::experimental::nullopt;
应脱离work
.
库基础TS 在[optional.nullopt ]:
should disengage work
.
The library fundamental TS specifies in [optional.nullopt]:
struct
nullopt_t
是用作唯一的空结构类型 类型,以指示可选对象的脱离状态.
The struct
nullopt_t
is an empty structure type used as a unique type to indicate a disengaged state for optional objects.
有一个合适的赋值运算符,[optional.object.assign]:
There is an appropriate assignment operator, [optional.object.assign]:
optional<T>& operator=(nullopt_t) noexcept;
效果:如果启用了*this
,则调用val->T::~T()
销毁所包含的值;否则,调用val->T::~T()
销毁所包含的值.否则没有效果.
Effects: If *this
is engaged calls val->T::~T()
to destroy the contained value; otherwise no effect.
为避免每次都构造一个nullopt_t
对象,已经声明了此类型的常量:
To avoid constructing a nullopt_t
object every time, a constant of this type is already declared:
struct nullopt_t{
请参见下文};
constexpr nullopt_t nullopt(
未指定);
struct nullopt_t{
see below};
constexpr nullopt_t nullopt(
unspecified);