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

154 KiB
Raw Permalink Blame History

[requirements]

16 Library introduction [library]

16.4 Library-wide requirements [requirements]

16.4.1 General [requirements.general]

1

#

Subclause [requirements] specifies requirements that apply to the entire C++ standard library.

[support] through [exec] and [depr] specify the requirements of individual entities within the library.

2

#

Requirements specified in terms of interactions between threads do not apply to programs having only a single thread of execution.

3

#

[organization] describes the library's contents and organization, [using] describes how well-formed C++ programs gain access to library entities,[utility.requirements] describes constraints on types and functions used with the C++ standard library,[constraints] describes constraints on well-formed C++ programs, and[conforming] describes constraints on conforming implementations.

16.4.2 Library contents and organization [organization]

16.4.2.1 General [organization.general]

1

#

[contents] describes the entities and macros defined in the C++ standard library.

[headers] lists the standard library headers and some constraints on those headers.

[compliance] lists requirements for a freestanding implementation of the C++ standard library.

16.4.2.2 Library contents [contents]

1

#

The C++ standard library provides definitions for the entities and macros described in the synopses of the C++ standard library headers ([headers]), unless otherwise specified.

2

#

All library entities exceptoperator new andoperator delete are defined within the namespacestd or namespaces nested within namespacestd.142

It is unspecified whether names declared in a specific namespace are declared directly in that namespace or in an inline namespace inside that namespace.143

3

#

Whenever an unqualified name other thanswap, make_error_code, make_error_condition,from_stream, orsubmdspan_mapping is used in the specification of a declaration D in [support] through [exec] or [depr], its meaning is established as-if by performing unqualified name lookup ([basic.lookup.unqual]) in the context of D.

[Note 1:

Argument-dependent lookup is not performed.

— end note]

Similarly, the meaning of a qualified-id is established as-if by performing qualified name lookup ([basic.lookup.qual]) in the context of D.

[Example 1:

The reference to is_array_v in the specification of std::to_array ([array.creation]) refers to ::std::is_array_v.

— end example]

[Note 2:

Operators in expressions ([over.match.oper]) are not so constrained; see [global.functions].

— end note]

The meaning of the unqualified name swap is established in an overload resolution context for swappable values ([swappable.requirements]).

The meanings of the unqualified namesmake_error_code, make_error_condition,from_stream, andsubmdspan_mapping are established as-if by performing argument-dependent lookup ([basic.lookup.argdep]).

142)142)

The C standard library headers ([support.c.headers]) also define names within the global namespace, while the C++ headers for C library facilities ([headers]) can also define names within the global namespace.

143)143)

This gives implementers freedom to use inline namespaces to support multiple configurations of the library.

16.4.2.3 Headers [headers]

1

#

Each element of the C++ standard library is declared or defined (as appropriate) in aheader.144

2

#

The C++ standard library provides theC++ library headers, shown in Table 24.

Table 24 — C++ library headers [tab:headers.cpp]

🔗
<forward_list>
🔗
🔗
🔗
🔗
<stop_token>
🔗
<hazard_pointer>
🔗
🔗
<initializer_list> <string_view>
🔗
<inplace_vector>
🔗
<system_error>
🔗
<text_encoding>
🔗
🔗
<condition_variable>
🔗
<type_traits>
🔗
<scoped_allocator>
🔗
🔗
<unordered_map>
🔗
<shared_mutex> <unordered_set>
🔗
🔗
<source_location>
🔗
🔗
<flat_map>
🔗
<flat_set>
🔗
<memory_resource>

3

#

The facilities of the C standard library are provided in theadditional headers shown in Table 25.145

Table 25 — C++ headers for C library facilities [tab:headers.cpp.c]

🔗
🔗
🔗

4

#

The headers listed in Table 24, or, for a freestanding implementation, the subset of such headers that are provided by the implementation, are collectively known as the importable C++ library headers.

[Note 1:

Importable C++ library headers can be imported ([module.import]).

— end note]

[Example 1: import ; // imports the header unit std::vector vi; // OK — end example]

5

#

Except as noted in [library] through [exec] and [depr], the contents of each header cname is the same as that of the corresponding header name.h as specified in the C standard library.

In the C++ standard library, however, the declarations (except for names which are defined as macros in C) are withinnamespace scope of the namespace std.

It is unspecified whether these names (including any overloads added in[support] through [exec] and [depr]) are first declared within the global namespace scope and are then injected into namespace std by explicitusing-declarations ([namespace.udecl]).

6

#

Names which are defined as macros in C shall be defined as macros in the C++ standard library, even if C grants license for implementation as functions.

[Note 2:

The names defined as macros in C include the following:assert, offsetof, setjmp, va_arg,va_end, and va_start.

— end note]

7

#

Names that are defined as functions in C shall be defined as functions in the C++ standard library.146

8

#

Identifiers that are keywords or operators in C++ shall not be defined as macros in C++ standard library headers.147

9

#

Subclause [support.c.headers] describes the effects of using the name.h (C header) form in a C++ program.148

10

#

ISO/IEC 9899:2024, Annex K describes a large number of functions, with associated types and macros, which “promote safer, more secure programming” than many of the traditional C library functions.

The names of the functions have a suffix of _s; most of them provide the same service as the C library function with the unsuffixed name, but generally take an additional argument whose value is the size of the result array.

If any C++ header is included, it is implementation-defined whether any of these names is declared in the global namespace.

(None of them is declared in namespace std.)

11

#

Table 26 lists the Annex K names that may be declared in some header.

These names are also subject to the restrictions of [macro.names].

Table 26 — Names from ISO/IEC 9899:2024, Annex K [tab:c.annex.k.names]

🔗
abort_handler_s
mbstowcs_s strncat_s vswscanf_s
🔗
asctime_s
memcpy_s strncpy_s vwprintf_s
🔗
bsearch_s
memmove_s strtok_s vwscanf_s
🔗
constraint_handler_t
memset_s swprintf_s wcrtomb_s
🔗
ctime_s
printf_s swscanf_s wcscat_s
🔗
errno_t
qsort_s tmpfile_s wcscpy_s
🔗
fopen_s
RSIZE_MAX TMP_MAX_S wcsncat_s
🔗
fprintf_s
rsize_t tmpnam_s wcsncpy_s
🔗
freopen_s
scanf_s vfprintf_s wcsnlen_s
🔗
fscanf_s
set_constraint_handler_s vfscanf_s wcsrtombs_s
🔗
fwprintf_s
snprintf_s vfwprintf_s wcstok_s
🔗
fwscanf_s
snwprintf_s vfwscanf_s wcstombs_s
🔗
getenv_s
sprintf_s vprintf_s wctomb_s
🔗
gets_s
sscanf_s vscanf_s wmemcpy_s
🔗
gmtime_s
strcat_s vsnprintf_s wmemmove_s
🔗
ignore_handler_s
strcpy_s vsnwprintf_s wprintf_s
🔗
localtime_s
strerrorlen_s vsprintf_s wscanf_s
🔗
L_tmpnam_s
strerror_s vsscanf_s
🔗
mbsrtowcs_s
strlen_s vswprintf_s

144)144)

A header is not necessarily a source file, nor are the sequences delimited by < and > in header names necessarily valid source file names ([cpp.include]).

145)145)

It is intentional that there is no C++ header for any of these C headers:<stdnoreturn.h>,<threads.h>.

146)146)

This disallows the practice, allowed in C, of providing a masking macro in addition to the function prototype.

The only way to achieve equivalent inline behavior in C++ is to provide a definition as an extern inline function.

147)147)

In particular, including the standard header <iso646.h> has no effect.

148)148)

The".h" headers dump all their names into the global namespace, whereas the newer forms keep their names in namespace std.

Therefore, the newer forms are the preferred forms for all uses except for C++ programs which are intended to be strictly compatible with C.

16.4.2.4 Modules [std.modules]

1

#

The C++ standard library provides the following C++ library modules.

2

#

The named module std exports declarations in namespace std that are provided by the importable C++ library headers (Table 24 or the subset provided by a freestanding implementation) and the C++ headers for C library facilities (Table 25).

It additionally exports declarations in the global namespace for the storage allocation and deallocation functions that are provided by .

3

#

The named module std.compat exports the same declarations as the named module std, and additionally exports

declarations in the global namespace corresponding to the declarations in namespace std that are provided by the C++ headers for C library facilities (Table 25), except the explicitly excluded declarations described in [support.c.headers.other] and

declarations provided by the headers <stdbit.h> and <stdckdint.h>.

4

#

It is unspecified to which module a declaration in the standard library is attached.

[Note 1:

Conforming implementations ensure that mixing#include and import does not result in conflicting attachments ([basic.link]).

— end note]

Recommended practice: Implementations should ensure such attachments do not preclude further evolution or decomposition of the standard library modules.

5

#

A declaration in the standard library denotes the same entity regardless of whether it was made reachable through including a header, importing a header unit, or importing a C++ library module.

6

#

Recommended practice: Implementations should avoid exporting any other declarations from the C++ library modules.

[Note 2:

Like all named modules, the C++ library modules do not make macros visible ([module.import]), such asassert ([cassert.syn]),errno ([cerrno.syn]),offsetof ([cstddef.syn]), andva_arg ([cstdarg.syn]).

— end note]

16.4.2.5 Freestanding implementations [compliance]

1

#

Two kinds of implementations are defined:hosted and freestanding ([intro.compliance]); the kind of the implementation isimplementation-defined.

For a hosted implementation, this document describes the set of available headers.

2

#

A freestanding implementation has animplementation-defined set of headers.

This set shall include at least the headers shown in Table 27.

Table 27 — C++ headers for freestanding implementations [tab:headers.cpp.fs]

🔗 Subclause Header
🔗
[support.types]
Common definitions
🔗
[cstdlib.syn]
C standard library
🔗
[support.limits]
Implementation properties , , ,
🔗
🔗
[cstdint.syn]
Integer types
🔗
[support.dynamic]
Dynamic memory management
🔗
[support.rtti]
Type identification
🔗
[support.srcloc]
Source location <source_location>
🔗
[support.exception]
Exception handling
🔗
[support.initlist]
Initializer lists <initializer_list>
🔗
[cmp]
Comparisons
🔗
[support.contract]
Contract-violation handling
🔗
[support.coroutine]
Coroutines support
🔗
[support.runtime]
Other runtime support
🔗
[concepts]
Concepts library
🔗
[errno]
Error numbers
🔗
[syserr]
System error support <system_error>
🔗
[debugging]
Debugging
🔗
[memory]
Memory
🔗
[type.traits]
Type traits <type_traits>
🔗
[ratio]
Compile-time rational arithmetic
🔗
[utility]
Utility components
🔗
[tuple]
Tuples
🔗
[optional]
Optional objects
🔗
[variant]
Variants
🔗
[expected]
Expected objects
🔗
[function.objects]
Function objects
🔗
[bit]
Bit manipulation
🔗
[stdbit.h.syn]
C-compatible bit manipulation <stdbit.h>
🔗
[array]
Class template array
🔗
[inplace.vector]
Class template inplace_vector <inplace_vector>
🔗
[views.contiguous]
Contiguous access
🔗
[views.multidim]
Multidimensional access
🔗
[iterators]
Iterators library
🔗
[ranges]
Ranges library
🔗
[algorithms]
Algorithms library ,
🔗
[execpol]
Execution policies
🔗
[string.view]
String view classes <string_view>
🔗
[string.classes]
String classes
🔗
[c.strings]
Null-terminated sequence utilities ,
🔗
[charconv]
Primitive numeric conversions
🔗
[rand]
Random number generation
🔗
[c.math]
Mathematical functions for floating-point types
🔗
[atomics]
Atomics
🔗

3

#

For each of the headers listed in Table 27, a freestanding implementation provides at least the freestanding items ([freestanding.item]) declared in the header.

4

#

The hosted library facilities are the set of facilities described in this document that are required for hosted implementations, but not required for freestanding implementations.

A freestanding implementation provides a (possibly empty) implementation-defined subset of the hosted library facilities.

Unless otherwise specified, the requirements on each declaration, entity, typedef-name, and macro provided in this way are the same as the corresponding requirements for a hosted implementation, except that not all of the members of the namespaces are required to be present.

5

#

A freestanding implementation provides deleted definitions ([dcl.fct.def.delete]) for a (possibly empty) implementation-defined subset of the namespace-scope functions and function templates from the hosted library facilities.

[Note 1:

An implementation can provide a deleted definition so that the result of overload resolution does not silently change when migrating a program from a freestanding implementation to a hosted implementation.

— end note]

16.4.3 Using the library [using]

16.4.3.1 Overview [using.overview]

1

#

Subclause [using] describes how a C++ program gains access to the facilities of the C++ standard library.

[using.headers] describes effects during translation phase 4, while [using.linkage] describes effects during phase 8.

16.4.3.2 Headers [using.headers]

1

#

The entities in the C++ standard library are defined in headers, whose contents are made available to a translation unit when it contains the appropriate#include preprocessing directive ([cpp.include]) or the appropriateimport declaration ([module.import]).

2

#

A translation unit may include library headers in any order ([lex.separate]).

Each may be included more than once, with no effect different from being included exactly once, except that the effect of including either or <assert.h> depends each time on the lexically current definition ofNDEBUG.149

3

#

A translation unit shall include a header only outside of anydeclaration or definition and, in the case of a module unit, only in its global-module-fragment, and shall include the header or import the corresponding header unit lexically before the first reference in that translation unit to any of the entities declared in that header.

No diagnostic is required.

149)149)

This is the same as the C standard library.

16.4.3.3 Linkage [using.linkage]

1

#

Entities in the C++ standard library have external linkage.

Unless otherwise specified, objects and functions have the defaultextern "C++" linkage ([dcl.link]).

2

#

Whether a name from the C standard library declared with external linkage hasextern "C" orextern "C++" linkage is implementation-defined.

It is recommended that an implementation useextern "C++" linkage for this purpose.150

3

#

Objects and functions defined in the library and required by a C++ program are included in the program prior to program startup.

4

#

See alsoreplacement functions,runtime changes.

150)150)

The only reliable way to declare an object or function signature from the C standard library is by including the header that declares it, notwithstanding the latitude granted in ISO/IEC 9899:2024, 7.1.4.

16.4.4 Requirements on types and expressions [utility.requirements]

16.4.4.1 General [utility.requirements.general]

1

#

[utility.arg.requirements] describes requirements on types and expressions used to instantiate templates defined in the C++ standard library.

[swappable.requirements] describes the requirements on swappable types and swappable expressions.

[nullablepointer.requirements] describes the requirements on pointer-like types that support null values.

[hash.requirements] describes the requirements on hash function objects.

[allocator.requirements] describes the requirements on storage allocators.

16.4.4.2 Template argument requirements [utility.arg.requirements]

1

#

The template definitions in the C++ standard library refer to various named requirements whose details are set out in Tables 28–35.

In these tables,

T denotes an object or reference type to be supplied by a C++ program instantiating a template,

a,b, andc denote values of type (possibly const) T,

s and t denote modifiable lvalues of type T,

u denotes an identifier,

rv denotes an rvalue of type T, and

v denotes an lvalue of type (possibly const) T or an rvalue of type const T.

2

#

In general, a default constructor is not required.

Certain container class member function signatures specify T() as a default argument.

T() shall be a well-defined expression ([dcl.init]) if one of those signatures is called using the default argument.

Table 28Cpp17EqualityComparable requirements [tab:cpp17.equalitycomparable]

🔗
Expression
Return type Requirement
🔗
a == b
decltype(a == b) models boolean-testable == is an equivalence relation, that is, it has the following properties:

For all a, a == a.
If a == b, then b == a.
If a == b and b == c, then a == c.

Table 29Cpp17LessThanComparable requirements [tab:cpp17.lessthancomparable]

🔗
Expression
Return type Requirement
🔗
a < b
decltype(a < b) models boolean-testable < is a strict weak ordering relation ([alg.sorting])

Table 30Cpp17DefaultConstructible requirements [tab:cpp17.defaultconstructible]

🔗
Expression
Post-condition
🔗
T t;
object t is default-initialized
🔗
T u{};
object u is value-initialized or aggregate-initialized
🔗
T() T{}
an object of type T is value-initialized or aggregate-initialized

Table 31Cpp17MoveConstructible requirements [tab:cpp17.moveconstructible]

🔗
Expression
Post-condition
🔗
T u = rv;
u is equivalent to the value of rv before the construction
🔗
T(rv)
T(rv) is equivalent to the value of rv before the construction
🔗
rv's state is unspecified
[Note 1:
rv must still meet the requirements of the library component that is using it.
The operations listed in those requirements must work as specified whether rv has been moved from or not. — end note]

Table 32Cpp17CopyConstructible requirements (in addition to Cpp17MoveConstructible) [tab:cpp17.copyconstructible]

🔗
Expression
Post-condition
🔗
T u = v;
the value of v is unchanged and is equivalent to u
🔗
T(v)
the value of v is unchanged and is equivalent to T(v)

Table 33Cpp17MoveAssignable requirements [tab:cpp17.moveassignable]

🔗
Expression
Return type Return value Post-condition
🔗
t = rv
T& t If t and rv do not refer to the same object, t is equivalent to the value of rv before the assignment
🔗
rv's state is unspecified.
[Note 2:
rv must still meet the requirements of the library component that is using it, whether or not t and rv refer to the same object.
The operations listed in those requirements must work as specified whether rv has been moved from or not. — end note]

Table 34Cpp17CopyAssignable requirements (in addition to Cpp17MoveAssignable) [tab:cpp17.copyassignable]

🔗
Expression
Return type Return value Post-condition
🔗
t = v
T& t t is equivalent to v, the value of v is unchanged

Table 35Cpp17Destructible requirements [tab:cpp17.destructible]

🔗
Expression
Post-condition
🔗
u.~T()
All resources owned by u are reclaimed, no exception is propagated.
🔗
[Note 3:
Array types and non-object types are not Cpp17Destructible. — end note]

16.4.4.3 Swappable requirements [swappable.requirements]

1

#

This subclause provides definitions for swappable types and expressions.

In these definitions, let t denote an expression of type T, and let u denote an expression of type U.

2

#

An object t is swappable with an object u if and only if

the expressions swap(t, u) and swap(u, t) are valid when evaluated in the context described below, and

these expressions have the following effects:

the object referred to by t has the value originally held by u and

the object referred to by u has the value originally held by t.

3

#

The context in which swap(t, u) and swap(u, t) are evaluated shall ensure that a binary non-member function named “swap” is selected via overload resolution on a candidate set that includes:

the two swap function templates defined in and

the lookup set produced by argument-dependent lookup.

[Note 1:

If T and U are both fundamental types or arrays of fundamental types and the declarations from the header are in scope, the overall lookup set described above is equivalent to that of the qualified name lookup applied to the expression std::swap(t, u) orstd::swap(u, t) as appropriate.

— end note]

[Note 2:

It is unspecified whether a library component that has a swappable requirement includes the header to ensure an appropriate evaluation context.

— end note]

4

#

An rvalue or lvalue t is swappable if and only if t is swappable with any rvalue or lvalue, respectively, of type T.

5

#

A type X meets the Cpp17Swappable requirements if lvalues of type X are swappable.

6

#

A type X meeting any of the iterator requirements ([iterator.requirements]) meets the Cpp17ValueSwappable requirements if, for any dereferenceable objectx of type X,*x is swappable.

7

#

[Example 1:

User code can ensure that the evaluation of swap calls is performed in an appropriate context under the various conditions as follows:#include #include // Preconditions: std::forward(t) is swappable with std::forward(u).template<class T, class U>void value_swap(T&& t, U&& u) {using std::swap; swap(std::forward(t), std::forward(u)); // OK, uses “swappable with'' conditions// for rvalues and lvalues}// Preconditions: T meets the Cpp17Swappable requirements.templatevoid lv_swap(T& t1, T& t2) {using std::swap; swap(t1, t2); // OK, uses swappable conditions for lvalues of type T}namespace N {struct A { int m; }; struct Proxy { A* a; }; Proxy proxy(A& a) { return Proxy{ &a }; }void swap(A& x, Proxy p) { std::swap(x.m, p.a->m); // OK, uses context equivalent to swappable// conditions for fundamental types}void swap(Proxy p, A& x) { swap(x, p); } // satisfy symmetry constraint}int main() {int i = 1, j = 2; lv_swap(i, j); assert(i == 2 && j == 1);

N::A a1 = { 5 }, a2 = { -5 }; value_swap(a1, proxy(a2)); assert(a1.m == -5 && a2.m == 5);}

— end example]

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

16.4.4.5 Cpp17Hash requirements [hash.requirements]

1

#

A type H meets the Cpp17Hash requirements if

it is a function object type ([function.objects]),

it meets the Cpp17CopyConstructible (Table 32) and Cpp17Destructible (Table 35) requirements, and

the expressions shown in Table 37 are valid and have the indicated semantics.

2

#

Given Key is an argument type for function objects of type H, in Table 37 h is a value of type (possibly const) H,u is an lvalue of type Key, and k is a value of a type convertible to (possibly const) Key.

Table 37Cpp17Hash requirements [tab:cpp17.hash]

🔗
Expression
Return type Requirement
🔗
h(k)
size_t The value returned shall depend only on the argument k for the duration of the program.
[Note 1:
Thus all evaluations of the expression h(k) with the same value for k yield the same result for a given execution of the program. — end note]
For two different values t1 and t2, the probability that h(t1) and h(t2) compare equal should be very small, approaching 1.0 / numeric_limits<size_t>::max().
🔗
h(u)
size_t Shall not modify u.

16.4.4.6 Cpp17Allocator requirements [allocator.requirements]

16.4.4.6.1 General [allocator.requirements.general]

1

#

The library describes a standard set of requirements for allocators, which are class-type objects that encapsulate the information about an allocation model.

This information includes the knowledge of pointer types, the type of their difference, the type of the size of objects in this allocation model, as well as the memory allocation and deallocation primitives for it.

All of the string types ([strings]), containers ([containers]) (except array and inplace_vector), string buffers and string streams ([input.output]), andmatch_results are parameterized in terms of allocators.

2

#

In [allocator.requirements],

T, U, C denote any cv-unqualified object type ([basic.types.general]),

X denotes an allocator class for type T,

Y denotes the corresponding allocator class for type U,

XX denotes the type allocator_traits,

YY denotes the type allocator_traits,

a, a1, a2 denote lvalues of type X,

u denotes the name of a variable being declared,

b denotes a value of type Y,

c denotes a pointer of type C* through which indirection is valid,

p denotes a value of type XX::pointer obtained by calling a1.allocate, where a1 == a,

q denotes a value of type XX::const_pointer obtained by conversion from a value p,

r denotes a value of type T& obtained by the expression *p,

w denotes a value of type XX::void_pointer obtained by conversion from a value p,

x denotes a value of type XX::const_void_pointer obtained by conversion from a value q or a value w,

y denotes a value of type XX::const_void_pointer obtained by conversion from a result value of YY::allocate, or else a value of type (possibly const) std::nullptr_t,

n denotes a value of type XX::size_type,

Args denotes a template parameter pack, and

args denotes a function parameter pack with the pattern Args&&.

3

#

The class template allocator_traits ([allocator.traits]) supplies a uniform interface to all allocator types.

This subclause describes the requirements on allocator types and thus on types used to instantiate allocator_traits.

A requirement is optional if a default for a given type or expression is specified.

Within the standard library allocator_traits template, an optional requirement that is not supplied by an allocator is replaced by the specified default type or expression.

[Note 1:

There are no program-defined specializations of allocator_traits.

— end note]

🔗

typename X::pointer

4

#

Remarks: Default: T*

🔗

typename X::const_pointer

5

#

Mandates: XX::pointer is convertible to XX::const_pointer.

6

#

Remarks: Default: pointer_traits<XX::pointer>::rebind

🔗

typename X::void_pointer typename Y::void_pointer

7

#

Mandates: XX::pointer is convertible to XX::void_pointer.

XX::void_pointer and YY::void_pointer are the same type.

8

#

Remarks: Default:pointer_traits<XX::pointer>::rebind

🔗

typename X::const_void_pointer typename Y::const_void_pointer

9

#

Mandates: XX::pointer, XX::const_pointer, and XX::void_pointer are convertible to XX::const_void_pointer.

XX::const_void_pointer and YY::const_void_pointer are the same type.

10

#

Remarks: Default:pointer_traits<XX::pointer>::rebind

🔗

typename X::value_type

11

#

Result: Identical to T.

🔗

typename X::size_type

12

#

Result: An unsigned integer type that can represent the size of the largest object in the allocation model.

13

#

Remarks: Default:make_unsigned_t<XX::difference_type>

🔗

typename X::difference_type

14

#

Result: A signed integer type that can represent the difference between any two pointers in the allocation model.

15

#

Remarks: Default:pointer_traits<XX::pointer>::difference_type

🔗

typename X::rebind<U>::other

16

#

Result: Y

17

#

Postconditions: For all U (including T),YY::rebind_alloc is X.

18

#

Remarks: If Allocator is a class template instantiation of the formSomeAllocator<T, Args>, where Args is zero or more type arguments, and Allocator does not supply a rebind member template, the standard allocator_traits template usesSomeAllocator<U, Args> in place of Allocator::rebind::other by default.

For allocator types that are not template instantiations of the above form, no default is provided.

19

#

[Note 2:

The member class template rebind of X is effectively a typedef template.

In general, if the name Allocator is bound to SomeAllocator, thenAllocator::rebind::other is the same type asSomeAllocator, whereSomeAllocator::value_type is T andSomeAllocator::value_type is U.

— end note]

🔗

*p

20

#

Result: T&

🔗

*q

21

#

Result: const T&

22

#

Postconditions: *q refers to the same object as *p.

🔗

p->m

23

#

Result: Type of T::m.

24

#

Preconditions: (*p).m is well-defined.

25

#

Effects: Equivalent to (*p).m.

🔗

q->m

26

#

Result: Type of T::m.

27

#

Preconditions: (*q).m is well-defined.

28

#

Effects: Equivalent to (*q).m.

🔗

static_cast<XX::pointer>(w)

29

#

Result: XX::pointer

30

#

Postconditions: static_cast<XX::pointer>(w) == p.

🔗

static_cast<XX::const_pointer>(x)

31

#

Result: XX::const_pointer

32

#

Postconditions: static_cast<XX::const_pointer>(x) == q.

🔗

pointer_traits<XX::pointer>::pointer_to(r)

33

#

Result: XX::pointer

34

#

Postconditions: Same as p.

🔗

a.allocate(n)

35

#

Result: XX::pointer

36

#

Effects: Memory is allocated for an array of n T and such an object is created but array elements are not constructed.

[Example 1:

When reusing storage denoted by some pointer value p,launder(reinterpret_cast<T*>(new (p) byte[n * sizeof(T)])) can be used to implicitly create a suitable array object and obtain a pointer to it.

— end example]

37

#

Throws: allocate may throw an appropriate exception.

38

#

[Note 3:

It is intended that a.allocate be an efficient means of allocating a single object of type T, even when sizeof(T) is small.

That is, there is no need for a container to maintain its own free list.

— end note]

39

#

Remarks: If n == 0, the return value is unspecified.

🔗

a.allocate(n, y)

40

#

Result: XX::pointer

41

#

Effects: Same as a.allocate(n).

The use of y is unspecified, but it is intended as an aid to locality.

42

#

Remarks: Default: a.allocate(n)

🔗

a.allocate_at_least(n)

43

#

Result: allocation_result<XX::pointer, XX::size_type>

44

#

Returns: allocation_result<XX::pointer, XX::size_type>{ptr, count} where ptr is memory allocated for an array of count T and such an object is created but array elements are not constructed, such that count ≥ n.

If n == 0, the return value is unspecified.

45

#

Throws: allocate_at_least may throw an appropriate exception.

46

#

Remarks: Default: {a.allocate(n), n}.

🔗

a.deallocate(p, n)

47

#

Result: (not used)

48

#

Preconditions:

  • (48.1)

    If p is memory that was obtained by a call to a.allocate_at_least, let ret be the value returned andreq be the value passed as the first argument of that call. p is equal to ret.ptr andn is a value such thatreq ≤ n ≤ ret.count.

  • (48.2)

    Otherwise, p is a pointer value obtained from allocate. n equals the value passed as the first argument to the invocation of allocate which returned p.

p has not been invalidated by an intervening call to deallocate.

49

#

Throws: Nothing.

🔗

a.max_size()

50

#

Result: XX::size_type

51

#

Returns: The largest value n that can meaningfully be passed to a.allocate(n).

52

#

Remarks: Default:numeric_limits<size_type>::max() / sizeof(value_type)

🔗

a1 == a2

53

#

Result: bool

54

#

Returns: true only if storage allocated from each can be deallocated via the other.

55

#

Throws: Nothing.

56

#

Remarks: operator== shall be reflexive, symmetric, and transitive.

🔗

a1 != a2

57

#

Result: bool

58

#

Returns: !(a1 == a2).

🔗

a == b

59

#

Result: bool

60

#

Returns: a == YY::rebind_alloc(b).

🔗

a != b

61

#

Result: bool

62

#

Returns: !(a == b).

🔗

X u(a); X u = a;

63

#

Postconditions: u == a

64

#

Throws: Nothing.

🔗

X u(b);

65

#

Postconditions: Y(u) == b and u == X(b).

66

#

Throws: Nothing.

🔗

X u(std::move(a)); X u = std::move(a);

67

#

Postconditions: The value of a is unchanged and is equal to u.

68

#

Throws: Nothing.

🔗

X u(std::move(b));

69

#

Postconditions: u is equal to the prior value of X(b).

70

#

Throws: Nothing.

🔗

a.construct(c, args...)

71

#

Result: (not used)

72

#

Effects: Constructs an object of type C at c.

73

#

Remarks: Default:construct_at(c, std::forward(args)...)

🔗

a.destroy(c)

74

#

Result: (not used)

75

#

Effects: Destroys the object at c.

76

#

Remarks: Default: destroy_at(c)

🔗

a.select_on_container_copy_construction()

77

#

Result: X

78

#

Returns: Typically returns either a or X().

79

#

Remarks: Default: return a;

🔗

typename X::propagate_on_container_copy_assignment

80

#

Result: Identical to or derived from true_type or false_type.

81

#

Returns: true_type only if an allocator of type X should be copied when the client container is copy-assigned; if so, X shall meet the Cpp17CopyAssignable requirements (Table 34) and the copy operation shall not throw exceptions.

82

#

Remarks: Default: false_type

🔗

typename X::propagate_on_container_move_assignment

83

#

Result: Identical to or derived from true_type or false_type.

84

#

Returns: true_type only if an allocator of type X should be moved when the client container is move-assigned; if so, X shall meet the Cpp17MoveAssignable requirements (Table 33) and the move operation shall not throw exceptions.

85

#

Remarks: Default: false_type

🔗

typename X::propagate_on_container_swap

86

#

Result: Identical to or derived from true_type or false_type.

87

#

Returns: true_type only if an allocator of type X should be swapped when the client container is swapped; if so,X shall meet the Cpp17Swappable requirements ([swappable.requirements]) and the swap operation shall not throw exceptions.

88

#

Remarks: Default: false_type

🔗

typename X::is_always_equal

89

#

Result: Identical to or derived from true_type or false_type.

90

#

Returns: true_type only if the expression a1 == a2 is guaranteed to be true for any two (possibly const) valuesa1, a2 of type X.

91

#

Remarks: Default: is_empty::type

92

#

An allocator type X shall meet theCpp17CopyConstructible requirements (Table 32).

The XX::pointer, XX::const_pointer, XX::void_pointer, andXX::const_void_pointer types shall meet theCpp17NullablePointer requirements (Table 36).

No constructor, comparison operator function, copy operation, move operation, or swap operation on these pointer types shall exit via an exception.

XX::pointer and XX::const_pointer shall also meet the requirements for a Cpp17RandomAccessIterator ([random.access.iterators]) and the additional requirement that, when p and (p + n) are dereferenceable pointer values for some integral value n,addressof(*(p + n)) == addressof(*p) + n is true.

93

#

Let x1 and x2 denote objects of (possibly different) typesXX::void_pointer, XX::const_void_pointer, XX::pointer, or XX::const_pointer.

Then, x1 and x2 areequivalently-valued pointer values, if and only if both x1 and x2 can be explicitly converted to the two corresponding objects px1 and px2 of type XX::const_pointer, using a sequence of static_casts using only these four types, and the expression px1 == px2 evaluates to true.

94

#

Let w1 and w2 denote objects of type XX::void_pointer.

Then for the expressionsw1 == w2 w1 != w2 either or both objects may be replaced by an equivalently-valued object of typeXX::const_void_pointer with no change in semantics.

95

#

Let p1 and p2 denote objects of type XX::pointer.

Then for the expressionsp1 == p2 p1 != p2 p1 < p2 p1 <= p2 p1 >= p2 p1 > p2 p1 - p2 either or both objects may be replaced by an equivalently-valued object of typeXX::const_pointer with no change in semantics.

96

#

An allocator may constrain the types on which it can be instantiated and the arguments for which its construct or destroy members may be called.

If a type cannot be used with a particular allocator, the allocator class or the call to construct or destroy may fail to instantiate.

97

#

If the alignment associated with a specific over-aligned type is not supported by an allocator, instantiation of the allocator for that type may fail.

The allocator also may silently ignore the requested alignment.

[Note 4:

Additionally, the member function allocate for that type can fail by throwing an object of typebad_alloc.

— end note]

98

#

[Example 2:

The following is an allocator class template supporting the minimal interface that meets the requirements of [allocator.requirements.general]:templatestruct SimpleAllocator {using value_type = T; SimpleAllocator(ctor args); template SimpleAllocator(const SimpleAllocator& other);

T* allocate(std::size_t n); void deallocate(T* p, std::size_t n); template bool operator==(const SimpleAllocator& rhs) const;};

— end example]

99

#

The following exposition-only concept defines the minimal requirements on an Allocator type.

templateconcept simple-allocator =requires(Alloc alloc, size_t n) {{ *alloc.allocate(n) } -> same_as<typename Alloc::value_type&>; { alloc.deallocate(alloc.allocate(n), n) }; } &&copy_constructible &&equality_comparable;

A type Alloc models simple-allocator if it meets the requirements of [allocator.requirements.general].

16.4.4.6.2 Allocator completeness requirements [allocator.requirements.completeness]

1

#

If X is an allocator class for type T,X additionally meets the allocator completeness requirements if, whether or not T is a complete type:

X is a complete type, and

all the member types of allocator_traits other than value_type are complete types.

16.4.5 Constraints on programs [constraints]

16.4.5.1 Overview [constraints.overview]

1

#

Subclause [constraints] describes restrictions on C++ programs that use the facilities of the C++ standard library.

The following subclauses specify constraints on the program's use of namespaces, its use of various reserved names, its use of headers, its use of standard library classes as base classes ([derived.classes]), its definitions of replacement functions, and its installation of handler functions during execution.

16.4.5.2 Namespace use [namespace.constraints]

16.4.5.2.1 Namespace std [namespace.std]

1

#

Unless otherwise specified, the behavior of a C++ program is undefined if it adds declarations or definitions to namespacestd or to a namespace within namespacestd.

2

#

Unless explicitly prohibited, a program may add a template specialization for any standard library class template to namespacestd provided that

the added declaration depends on at least one program-defined type, and

the specialization meets the standard library requirements for the original template.151

3

#

The behavior of a C++ program is undefined if it declares an explicit or partial specialization of any standard library variable template, except where explicitly permitted by the specification of that variable template.

[Note 1:

The requirements on an explicit or partial specialization are stated by each variable template that grants such permission.

— end note]

4

#

The behavior of a C++ program is undefined if it declares

an explicit specialization of any member function of a standard library class template, or

an explicit specialization of any member function template of a standard library class or class template, or

an explicit or partial specialization of any member class template of a standard library class or class template, or

a deduction guide for any standard library class template.

5

#

A program may explicitly instantiate a class template defined in the standard library only if the declaration

depends on the name of at least one program-defined type, and

the instantiation meets the standard library requirements for the original template.

6

#

Let F denote a standard library function ([global.functions]), a standard library static member function, or an instantiation of a standard library function template.

Unless F is designated an addressable function, the behavior of a C++ program is unspecified (possibly ill-formed) if it explicitly or implicitly attempts to form a pointer to F.

[Note 2:

Possible means of forming such pointers include application of the unary & operator ([expr.unary.op]),addressof ([specialized.addressof]), or a function-to-pointer standard conversion ([conv.func]).

— end note]

Moreover, the behavior of a C++ program is unspecified (possibly ill-formed) if it attempts to form a reference to F or if it attempts to form a pointer-to-member designating either a standard library non-static member function ([member.functions]) or an instantiation of a standard library member function template.

7

#

Let F denote a standard library function or function template.

Unless F is designated an addressable function, it is unspecified if or how a reflection value designating the associated entity can be formed.

[Note 3:

For example, it is possible that std::meta::members_of will not return reflections of standard library functions that an implementation handles through an extra-linguistic mechanism.

— end note]

8

#

Let C denote a standard library class or class template specialization.

It is unspecified if or how a reflection value can be formed to any private member of C, or what the names of such members may be.

9

#

A translation unit shall not declare namespace std to be an inline namespace ([namespace.def]).

151)151)

Any library code that instantiates other library templates must be prepared to work adequately with any user-supplied specialization that meets the minimum requirements of this document.

16.4.5.2.2 Namespace posix [namespace.posix]

1

#

The behavior of a C++ program is undefined if it adds declarations or definitions to namespaceposix or to a namespace within namespaceposix unless otherwise specified.

The namespace posix is reserved for use by ISO/IEC/IEEE 9945 and other POSIX standards.

16.4.5.2.3 Namespaces for future standardization [namespace.future]

1

#

Top-level namespaces whose namespace-name consists of std followed by one or more digits ([lex.name]) are reserved for future standardization.

The behavior of a C++ program is undefined if it adds declarations or definitions to such a namespace.

[Example 1:

The top-level namespace std2 is reserved for use by future revisions of this International Standard.

— end example]

16.4.5.3 Reserved names [reserved.names]

16.4.5.3.1 General [reserved.names.general]

1

#

The C++ standard library reserves the following kinds of names:

macros

global names

names with external linkage

2

#

If a program declares or defines a name in a context where it is reserved, other than as explicitly allowed by [library], its behavior is undefined.

16.4.5.3.2 Zombie names [zombie.names]

1

#

In namespace std, the names shown in Table 38 are reserved for previous standardization:

Table 38 — Zombie names in namespace std [tab:zombie.names.std]

🔗
auto_ptr
generate_header pointer_to_binary_function
🔗
auto_ptr_ref
get_pointer_safety pointer_to_unary_function
🔗
binary_function
get_temporary_buffer ptr_fun
🔗
binary_negate
get_unexpected random_shuffle
🔗
bind1st
gets raw_storage_iterator
🔗
bind2nd
is_literal_type result_of
🔗
binder1st
is_literal_type_v result_of_t
🔗
binder2nd
istrstream return_temporary_buffer
🔗
codecvt_mode
little_endian set_unexpected
🔗
codecvt_utf16
mem_fun1_ref_t strstream
🔗
codecvt_utf8
mem_fun1_t strstreambuf
🔗
codecvt_utf8_utf16
mem_fun_ref_t unary_function
🔗
const_mem_fun1_ref_t
mem_fun_ref unary_negate
🔗
const_mem_fun1_t
mem_fun_t uncaught_exception
🔗
const_mem_fun_ref_t
mem_fun undeclare_no_pointers
🔗
const_mem_fun_t
not1 undeclare_reachable
🔗
consume_header
not2 unexpected_handler
🔗
declare_no_pointers
ostrstream wbuffer_convert
🔗
declare_reachable
pointer_safety wstring_convert

2

#

The names shown in Table 39 are reserved as members for previous standardization, and may not be used as a name for object-like macros in portable code:

Table 39 — Zombie object-like macros [tab:zombie.names.objmacro]

🔗
argument_type
op second_argument_type
🔗
first_argument_type
open_mode seek_dir
🔗
io_state
preferred strict

3

#

The names shown in Table 40 are reserved as member functions for previous standardization, and may not be used as a name for function-like macros in portable code:

Table 40 — Zombie function-like macros [tab:zombie.names.fnmacro]

🔗
converted
freeze from_bytes pcount stossc to_bytes

4

#

The header names shown in Table 41 are reserved for previous standardization:

Table 41 — Zombie headers [tab:zombie.names.header]

🔗
🔗

16.4.5.3.3 Macro names [macro.names]

1

#

A translation unit that includes a standard library header shall not#define or #undef names declared in any standard library header.

16.4.5.3.4 External linkage [extern.names]

1

#

Each name declared as an object with external linkagein a header is reserved to the implementation to designate that library object with external linkage,152 both in namespace std and in the global namespace.

2

#

Eachglobal function signature declared withexternal linkage in a header is reserved to the implementation to designate that function signature withexternal linkage.153

3

#

Each name from the C standard library declared with external linkageis reserved to the implementation for use as a name withextern "C" linkage, both in namespace std and in the global namespace.

4

#

Each function signature from the C standard library declared withexternal linkage is reserved to the implementation for use as a function signature with bothextern "C" andextern "C++" linkage,154 or as a name of namespace scope in the global namespace.

152)152)

The list of such reserved names includeserrno, declared or defined in .

153)153)

The list of such reserved function signatures with external linkage includessetjmp(jmp_buf), declared or defined in , andva_end(va_list), declared or defined in.

154)154)

The function signatures declared in,, and are always reserved, notwithstanding the restrictions imposed in subclause 4.5.1 of Amendment 1 to the C Standard for these headers.

16.4.5.3.5 Types [extern.types]

1

#

For each type T from the C standard library, the types::T andstd::T are reserved to the implementation and, when defined,::T shall be identical tostd::T.

16.4.5.3.6 User-defined literal suffixes [usrlit.suffix]

1

#

Literal suffix identifiers ([over.literal]) that do not start with an underscore are reserved for future standardization.

Literal suffix identifiers that contain a double underscore__are reserved for use by C++ implementations.

16.4.5.4 Headers [alt.headers]

1

#

If a file with a name equivalent to the derived file name for one of the C++ standard library headers is not provided as part of the implementation, and a file with that name is placed in any of the standard places for a source file to be included, the behavior is undefined.

16.4.5.5 Derived classes [derived.classes]

1

#

Virtual member function signatures definedfor a base class in the C++ standardlibrary may be overridden in a derived class defined in the program ([class.virtual]).

16.4.5.6 Replacement functions [replacement.functions]

1

#

If a function defined in[support] through [exec] and [depr] is specified as replaceable ([dcl.fct.def.replace]), the description of function semantics apply to both the default version defined by the C++ standard library and the replacement function defined by the program.

16.4.5.7 Handler functions [handler.functions]

1

#

The C++ standard library provides a default version of the following handler function ([support]):

terminate_handler

2

#

A C++ program may install different handler functions during execution, by supplying a pointer to a function defined in the program or the library as an argument to (respectively):

set_new_handler

set_terminate

See also subclauses [alloc.errors], Storage allocation errors, and [support.exception], Exception handling.

3

#

A C++ program can get a pointer to the current handler function by calling the following functions:

get_new_handler

get_terminate

4

#

Calling the set_* and get_* functions shall not incur a data race ([intro.races]).

A call to any of the set_* functions synchronizes with subsequent calls to the sameset_* function and to the corresponding get_* function.

16.4.5.8 Other functions [res.on.functions]

1

#

In certain cases (replacement functions, handler functions, operations on types used to instantiate standard library template components), the C++ standard library depends on components supplied by a C++ program.

If these components do not meet their requirements, this document places no requirements on the implementation.

2

#

In particular, the behavior is undefined in the following cases:

  • (2.1)

    For replacement functions ([replacement.functions]), if the installed replacement function does not implement the semantics of the applicableRequired behavior: paragraph.

  • (2.2)

    For handler functions ([new.handler], [terminate.handler]), if the installed handler function does not implement the semantics of the applicableRequired behavior: paragraph.

  • (2.3)

    For types used as template arguments when instantiating a template component, if the operations on the type do not implement the semantics of the applicableRequirements subclause ([allocator.requirements], [container.requirements], [iterator.requirements], [algorithms.requirements], [numeric.requirements]). Operations on such types can report a failure by throwing an exception unless otherwise specified.

  • (2.4)

    If any replacement function or handler function or destructor operation exits via an exception, unless specifically allowed in the applicableRequired behavior: paragraph.

  • (2.5)

    If an incomplete type ([basic.types.general]) is used as a template argument when instantiating a template component or evaluating a concept, unless specifically allowed for that component.

16.4.5.9 Function arguments [res.on.arguments]

1

#

Each of the following applies to all argumentsto functions defined in the C++ standard library, unless explicitly stated otherwise.

  • (1.1)

    If an argument to a function has an invalid value (suchas a value outside the domain of the function or a pointer invalid for its intended use), the behavior is undefined.

  • (1.2)

    If a function argument is described as being an array,the pointer actually passed to the function shall have a value such that all address computations and accesses to objects (that would be valid if the pointer did point to the first element of such an array) are in fact valid.

  • (1.3)

    If a function argument is bound to an rvalue reference parameter, the implementation may assume that this parameter is a unique reference to this argument, except that the argument passed to a move assignment operator may be a reference to *this ([lib.types.movedfrom]). [Note 1: If the type of a parameter is a forwarding reference ([temp.deduct.call]) that is deduced to an lvalue reference type, then the argument is not bound to an rvalue reference. — end note] [Note 2: If a program casts an lvalue to an xvalue while passing that lvalue to a library function (e.g., by calling the function with the argument std::move(x)), the program is effectively asking that function to treat that lvalue as a temporary object. The implementation is free to optimize away aliasing checks which would possibly be needed if the argument was an lvalue. — end note]

16.4.5.10 Library object access [res.on.objects]

1

#

The behavior of a program is undefined if calls to standard library functions from different threads may introduce a data race.

The conditions under which this may occur are specified in [res.on.data.races].

[Note 1:

Modifying an object of a standard library type that is shared between threads risks undefined behavior unless objects of that type are explicitly specified as being shareable without data races or the user supplies a locking mechanism.

— end note]

2

#

If an object of a standard library type is accessed, and the beginning of the object's lifetime does not happen before the access, or the access does not happen before the end of the object's lifetime, the behavior is undefined unless otherwise specified.

[Note 2:

This applies even to objects such as mutexes intended for thread synchronization.

— end note]

16.4.5.11 Semantic requirements [res.on.requirements]

1

#

A sequence Args of template arguments is said tomodel a concept C if Args satisfies C ([temp.constr.decl]) and meets all semantic requirements (if any) given in the specification of C.

2

#

If the validity or meaning of a program depends on whether a sequence of template arguments models a concept, and the concept is satisfied but not modeled, the program is ill-formed, no diagnostic required.

3

#

If the semantic requirements of a declaration's constraints ([structure.requirements]) are not modeled at the point of use, the program is ill-formed, no diagnostic required.

16.4.6 Conforming implementations [conforming]

16.4.6.1 Overview [conforming.overview]

1

#

Subclause [conforming] describes the constraints upon, and latitude of, implementations of the C++ standard library.

2

#

An implementation's use of

headers is discussed in [res.on.headers],

macros in [res.on.macro.definitions],

non-member functions in [global.functions],

member functions in [member.functions],

data race avoidance in [res.on.data.races],

access specifiers in [protection.within.classes],

class derivation in [derivation],

exceptions in [res.on.exception.handling], and

contract assertions in [res.contract.assertions].

16.4.6.2 Headers [res.on.headers]

1

#

A C++ header may include other C++ headers.

A C++ header shall provide the declarations and definitions that appear in its synopsis.

A C++ header shown in its synopsis as including other C++ headers shall provide the declarations and definitions that appear in the synopses of those other headers.

2

#

Certain types and macros are defined in more than one header.

Every such entity shall be defined such that any header that defines it may be included after any other header that also defines it ([basic.def.odr]).

3

#

The C standard library headers shall include only their corresponding C++ standard library header, as described in [headers].

16.4.6.3 Restrictions on macro definitions [res.on.macro.definitions]

1

#

The names and global function signatures described in [contents] are reserved to the implementation.

2

#

All object-like macros defined by the C standard library and described in this Clause as expanding to integral constant expressions are also suitable for use in #if preprocessing directives, unless explicitly stated otherwise.

16.4.6.4 Non-member functions [global.functions]

1

#

It is unspecified whether any non-member functions in the C++ standard library are defined asinline.

2

#

A call to a non-member function signature described in [support] through [exec] and[depr] shall behave as if the implementation declared no additional non-member function signatures.155

3

#

An implementation shall not declare a non-member function signature with additional default arguments.

4

#

Unless otherwise specified, calls made by functions in the standard library to non-operator, non-member functions do not use functions from another namespace which are found through argument-dependent name lookup ([basic.lookup.argdep]).

[Note 1:

The phrase “unless otherwise specified” applies to cases such as the swappable with requirements ([swappable.requirements]).

The exception for overloaded operators allows argument-dependent lookup in cases like that ofostream_iterator::operator=:

Effects: *out_stream << value;if (delim != 0)*out_stream << delim;return *this;

— end note]

155)155)

A valid C++ program always calls the expected library non-member function.

An implementation can also define additional non-member functions that would otherwise not be called by a valid C++ program.

16.4.6.5 Member functions [member.functions]

1

#

It is unspecified whether any member functions in the C++ standard library are defined asinline.

2

#

For a non-virtual member function described in the C++ standard library, an implementation may declare a different set of member function signatures, provided that any call to the member function that would select an overload from the set of declarations described in this document behaves as if that overload were selected.

[Note 1:

For instance, an implementation can add parameters with default values, or replace a member function with default arguments with two or more member functions with equivalent behavior, or add additional signatures for a member function name.

— end note]

16.4.6.6 Friend functions [hidden.friends]

1

#

Whenever this document specifies a friend declaration of a function or function template within a class or class template definition, that declaration shall be the only declaration of that function or function template provided by an implementation.

[Note 1:

In particular, a conforming implementation does not provide any additional declarations of that function or function template at namespace scope.

— end note]

[Note 2:

Such a friend function or function template declaration is known as a hidden friend, as it is visible neither to ordinary unqualified lookup ([basic.lookup.unqual]) nor to qualified lookup ([basic.lookup.qual]).

— end note]

16.4.6.7 Constexpr functions and constructors [constexpr.functions]

1

#

This document explicitly requires that certain standard library functions areconstexpr ([dcl.constexpr]).

An implementation shall not declare any standard library function signature as constexpr except for those where it is explicitly required.

Within any header that provides any non-defining declarations of constexpr functions or constructors an implementation shall provide corresponding definitions.

16.4.6.8 Requirements for stable algorithms [algorithm.stable]

1

#

When the requirements for an algorithm state that it is “stable” without further elaboration, it means:

  • (1.1)

    For the sort algorithms the relative order of equivalent elements is preserved.

  • (1.2)

    For the remove and copy algorithms the relative order of the elements that are not removed is preserved.

  • (1.3)

    For the merge algorithms, for equivalent elements in the original two ranges, the elements from the first range (preserving their original order) precede the elements from the second range (preserving their original order).

16.4.6.9 Reentrancy [reentrancy]

1

#

Except where explicitly specified in this document, it is implementation-defined which functions in the C++ standard library may be recursively reentered.

16.4.6.10 Data race avoidance [res.on.data.races]

1

#

This subclause specifies requirements that implementations shall meet to preventdata races.

Every standard library function shall meet each requirement unless otherwise specified.

Implementations may prevent data races in cases other than those specified below.

2

#

A C++ standard library function shall not directly or indirectly access objects ([intro.multithread]) accessible by threads other than the current thread unless the objects are accessed directly or indirectly via the function's arguments, including this.

3

#

A C++ standard library function shall not directly or indirectly modify objects ([intro.multithread]) accessible by threads other than the current thread unless the objects are accessed directly or indirectly via the function's non-const arguments, including this.

4

#

[Note 1:

This means, for example, that implementations can't use an object with static storage duration for internal purposes without synchronization because doing so can cause a data race even in programs that do not explicitly share objects between threads.

— end note]

5

#

A C++ standard library function shall not access objects indirectly accessible via its arguments or via elements of its container arguments except by invoking functions required by its specification on those container elements.

6

#

Operations on iterators obtained by calling a standard library container or string member function may access the underlying container, but shall not modify it.

[Note 2:

In particular, container operations that invalidate iterators conflict with operations on iterators associated with that container.

— end note]

7

#

Implementations may share their own internal objects between threads if the objects are not visible to users and are protected against data races.

8

#

Unless otherwise specified, C++ standard library functions shall perform all operations solely within the current thread if those operations have effects that arevisible to users.

9

#

[Note 3:

This allows implementations to parallelize operations if there are no visibleside effects.

— end note]

16.4.6.11 Properties of library classes [library.class.props]

1

#

Unless explicitly stated otherwise, it is unspecified whether any class described in [support] through [exec] and[depr] is a trivially copyable class, a standard-layout class, or an implicit-lifetime class ([class.prop]).

2

#

Unless explicitly stated otherwise, it is unspecified whether any class for which trivial relocation (i.e., the effects oftrivially_relocate ([obj.lifetime])) would be semantically equivalent to move-construction of the destination object followed by destruction of the source object is a trivially relocatable class ([class.prop]).

3

#

Unless explicitly stated otherwise, it is unspecified whether a class C is a replaceable class ([class.prop]) if assigning an xvalue a of type C to an object b of type C is semantically equivalent to destroying b and then constructing from a inb's place.

16.4.6.12 Protection within classes [protection.within.classes]

1

#

It is unspecified whether any function signature or class described in[support] through [exec] and [depr] is a friend of another class in the C++ standard library.

16.4.6.13 Derived classes [derivation]

1

#

An implementation may derive any class in the C++ standard library from a class with a name reserved to the implementation.

2

#

Certain classes defined in the C++ standard library are required to be derived from other classes in the C++ standard library.

An implementation may derive such a class directly from the required base or indirectly through a hierarchy of base classes with names reserved to the implementation.

3

#

In any case:

Every base class described asvirtual shall be virtual;

Every base class not specified asvirtual shall not be virtual;

Unless explicitly stated otherwise, types with distinct names shall be distinct types. [Note 1: There is an implicit exception to this rule for types that are described as synonyms ([dcl.typedef], [namespace.udecl]), such assize_t ([support.types]) andstreamoff ([stream.types]). — end note]

4

#

All types specified in the C++ standard library shall be non-final types unless otherwise specified.

16.4.6.14 Restrictions on exception handling [res.on.exception.handling]

1

#

Any of the functions defined in the C++ standard librarycan report a failure by throwing an exception of a type described in its Throws: paragraph, or of a type derived from a type named in the Throws: paragraph that would be caught by a handler ([except.handle]) for the base type.

2

#

Functions from the C standard library shall not throw exceptions156 except when such a function calls a program-supplied function that throws an exception.157

3

#

Destructor operations defined in the C++ standard library shall not throw exceptions.

Every destructor in the C++ standard library shall behave as if it had a non-throwing exception specification ([except.spec]).

4

#

Functions defined in the C++ standard librarythat do not have a Throws: paragraph but do have a potentially-throwing exception specification may throw implementation-defined exceptions.158

Implementations should report errors by throwing exceptions of or derived from the standard exception classes ([bad.alloc], [support.exception], [std.exceptions]).

5

#

An implementation may strengthen the exception specification for a non-virtual function by adding a non-throwing exception specification.

156)156)

That is, the C standard library functions can all be treated as if they are marked noexcept.

This allows implementations to make performance optimizations based on the absence of exceptions at runtime.

157)157)

The functionsqsort() andbsearch() ([alg.c.library]) meet this condition.

158)158)

In particular, they can report a failure to allocate storage by throwing an exception of typebad_alloc, or a class derived frombad_alloc ([bad.alloc]).

16.4.6.15 Contract assertions [res.contract.assertions]

1

#

Unless specified otherwise, an implementation may check the specified preconditions and postconditions of a function in the C++ standard library using contract assertions ([basic.contract], [structure.specifications]).

16.4.6.16 Value of error codes [value.error.codes]

1

#

Certain functions in the C++ standard library report errors via aerror_code ([syserr.errcode.overview]) object.

That object'scategory() member shall return system_category() for errors originating from the operating system, or a reference to animplementation-defined error_category object for errors originating elsewhere.

The implementation shall define the possible values of value() for each of these error categories.

[Example 1:

For operating systems that are based on POSIX, implementations should define the std::system_category() values as identical to the POSIX errno values, with additional values as defined by the operating system's documentation.

Implementations for operating systems that are not based on POSIX should define values identical to the operating system's values.

For errors that do not originate from the operating system, the implementation may provide enums for the associated values.

— end example]

16.4.6.17 Moved-from state of library types [lib.types.movedfrom]

1

#

Objects of types defined in the C++ standard library may be moved from ([class.copy.ctor]).

Move operations may be explicitly specified or implicitly generated.

Unless otherwise specified, such moved-from objects shall be placed in a valid but unspecified state ([defns.valid]).

2

#

An object of a type defined in the C++ standard library may be move-assigned ([class.copy.assign]) to itself.

Unless otherwise specified, such an assignment places the object in a valid but unspecified state.