在线文档教程

NullablePointer

C++概念:自C++11%29以来NullablePoter%28

指定该类型是一个类似指针的对象,可与std::nullptr_t物品。

所需

该类型必须满足以下所有概念要求:

  • EqualityComparable

  • DefaultConstructible

  • CopyConstructible

  • CopyAssignable

  • Destructible

此外,类型的值初始化对象必须生成该类型的空值。此空值只能与其本身等效。类型的默认初始化可能具有不确定值。

类型的对象必须在上下文上可转换为bool。如果该值与其空值等效,则此转换的效果返回false,否则返回true。

此类型执行的任何操作都不会引发异常。

类型必须满足以下附加表达式,给定两个值pq那种类型的npstd::nullptr_t类型%28可能const合格%29:

ExpressionEffects
Type p(np Type p = np;Afterwards, p is equivalent to nullptr
Type(np)a temporary object that is equivalent to nullptr
p = npMust return a Type&, and afterwards, p is equivalent to nullptr
p != qMust return a value that is contextually convertible to bool. The effect is !(p == q).
p == np np == p.Must return a value that is contextually convertible to bool. The effect is (p == Type()).
p != np np != p.Must return a value that is contextually convertible to bool. The effect is !(p == np).

注记

注意取消引用%28operator*或operator->%29不需要NullablePointertype。满足这些要求的极简型是。

二次

class handle { int id; public: handle(std::nullptr_t = nullptr) : id(0) { } explicit operator bool() { return id != 0; } friend bool operator ==(handle l, handle r) { return l.id == r.id; } friend bool operator !=(handle l, handle r) { return !(l == r } };

二次

标准库

以下类型必须满足NullablePointer*

  • 成员类型X::pointer,,,X::const_pointer,,,X::void_pointerX::const_void_pointer每一个Allocator类型X

  • 成员类型X::pointerstd::unique_ptr

  • 类型std::exception_ptr

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cpPreference.com/w/cpp/Concept/NullablePoint