Files
cppdraft_translate/cppdraft/nullablepointer/requirements.md
2025-10-25 03:02:53 +03:00

4.8 KiB
Raw Blame History

[nullablepointer.requirements]

16 Library introduction [library]

16.4 Library-wide requirements [requirements]

16.4.4 Requirements on types and expressions [utility.requirements]

16.4.4.4 Cpp17NullablePointer requirements [nullablepointer.requirements]

1

#

A Cpp17NullablePointer type is a pointer-like type that supports null values.

A type P meets the Cpp17NullablePointer requirements if

P meets the Cpp17EqualityComparable,Cpp17DefaultConstructible, Cpp17CopyConstructible, Cpp17CopyAssignable,Cpp17Swappable, and Cpp17Destructible requirements,

the expressions shown in Table 36 are valid and have the indicated semantics, and

P meets all the other requirements of this subclause.

2

#

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 or erroneous value.

[Note 1:

Operations involving indeterminate values can cause undefined behavior, and operations involving erroneous values can cause erroneous behavior ([basic.indet]).

— end note]

3

#

An object p of type P can becontextually converted to bool.

The effect shall be as if p != nullptr had been evaluated in place of p.

4

#

No operation which is part of the Cpp17NullablePointer requirements shall exit via an exception.

5

#

In Table 36, 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 36Cpp17NullablePointer requirements [tab:cpp17.nullablepointer]

🔗
Expression
Return type Operational semantics
🔗
P u(np);
Postconditions: u == nullptr
🔗
P u = np;
🔗
P(np)
Postconditions: P(np) == nullptr
🔗
t = np
P& Postconditions: t == nullptr
🔗
a != b
decltype(a != b) models boolean-testable !(a == b)
🔗
a == np
decltype(a == np) and decltype(np == a) each model boolean-testable a == P()
🔗
np == a
🔗
a != np
decltype(a != np) and decltype(np != a) each model boolean-testable !(a == np)
🔗
np != a