20 Library introduction [library]

20.5 Library-wide requirements [requirements]

20.5.3 Requirements on types and expressions [utility.requirements] NullablePointer requirements [nullablepointer.requirements]

A NullablePointer type is a pointer-like type that supports null values.
A type P meets the requirements of NullablePointer if:
  • P satisfies the requirements of EqualityComparable, DefaultConstructible, CopyConstructible, CopyAssignable, and Destructible,
  • lvalues of type P are swappable,
  • the expressions shown in Table 28 are valid and have the indicated semantics, and
  • P satisfies all the other requirements of this subclause.
A value-initialized object of type P produces the null value of the type.
The null value shall be equivalent only to itself.
A default-initialized object of type P may have an indeterminate value.
Operations involving indeterminate values may cause undefined behavior.
end note
An object p of type P can be contextually converted to bool.
The effect shall be as if p != nullptr had been evaluated in place of p.
No operation which is part of the NullablePointer requirements shall exit via an exception.
In Table 28, u denotes an identifier, t denotes a non-const lvalue of type P, a and b denote values of type (possibly const) P, and np denotes a value of type (possibly const) std​::​nullptr_­t.
Table 28NullablePointer requirements
Return type
Operational semantics
P u(np);
Postconditions: u == nullptr
P u = np;
Postconditions: P(np) == nullptr
t = np
Postconditions: t == nullptr
a != b
contextually convertible to bool
!(a == b)
a == np
contextually convertible to bool
a == P()
np == a
a != np
contextually convertible to bool
!(a == np)
np != a