3193 lines
154 KiB
Markdown
3193 lines
154 KiB
Markdown
[requirements]
|
||
|
||
# 16 Library introduction [[library]](./#library)
|
||
|
||
## 16.4 Library-wide requirements [requirements]
|
||
|
||
### [16.4.1](#general) General [[requirements.general]](requirements.general)
|
||
|
||
[1](#general-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1087)
|
||
|
||
Subclause [requirements] specifies requirements that apply to the entire C++ standard library[.](#general-1.sentence-1)
|
||
|
||
[[support]](support "17 Language support library") through [[exec]](exec "33 Execution control library") and [[depr]](depr "Annex D (normative) Compatibility features") specify the requirements of individual entities within the library[.](#general-1.sentence-2)
|
||
|
||
[2](#general-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1092)
|
||
|
||
Requirements specified in terms of interactions between threads do not apply to
|
||
programs having only a single thread of execution[.](#general-2.sentence-1)
|
||
|
||
[3](#general-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1096)
|
||
|
||
[[organization]](#organization "16.4.2 Library contents and organization") describes the library's contents and
|
||
organization, [[using]](#using "16.4.3 Using the library") describes how well-formed C++ programs gain access to library
|
||
entities,[[utility.requirements]](#utility.requirements "16.4.4 Requirements on types and expressions") describes constraints on types and functions used with
|
||
the C++ standard library,[[constraints]](#constraints "16.4.5 Constraints on programs") describes constraints on well-formed C++ programs, and[[conforming]](#conforming "16.4.6 Conforming implementations") describes constraints on conforming implementations[.](#general-3.sentence-1)
|
||
|
||
### [16.4.2](#organization) Library contents and organization [[organization]](organization)
|
||
|
||
#### [16.4.2.1](#organization.general) General [[organization.general]](organization.general)
|
||
|
||
[1](#organization.general-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1109)
|
||
|
||
[[contents]](#contents "16.4.2.2 Library contents") describes the entities and macros defined in the C++ standard library[.](#organization.general-1.sentence-1)
|
||
|
||
[[headers]](#headers "16.4.2.3 Headers") lists the standard library headers and some constraints on those headers[.](#organization.general-1.sentence-2)
|
||
|
||
[[compliance]](#compliance "16.4.2.5 Freestanding implementations") lists requirements for a freestanding implementation of the C++
|
||
standard library[.](#organization.general-1.sentence-3)
|
||
|
||
#### [16.4.2.2](#contents) Library contents [[contents]](contents)
|
||
|
||
[1](#contents-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1117)
|
||
|
||
The C++ standard library provides definitions
|
||
for the entities and macros described in the synopses
|
||
of the C++ standard library headers ([[headers]](#headers "16.4.2.3 Headers")),
|
||
unless otherwise specified[.](#contents-1.sentence-1)
|
||
|
||
[2](#contents-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1123)
|
||
|
||
All library entities exceptoperator new andoperator delete are defined within the namespacestd or namespaces nested within namespacestd[.](#contents-2.sentence-1)[142](#footnote-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.")
|
||
|
||
It is unspecified whether names declared in a specific namespace are declared
|
||
directly in that namespace or in an inline namespace inside that
|
||
namespace[.](#contents-2.sentence-2)[143](#footnote-143 "This gives implementers freedom to use inline namespaces to support multiple configurations of the library.")
|
||
|
||
[3](#contents-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1146)
|
||
|
||
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]](support "17 Language support library") through [[exec]](exec "33 Execution control library") or [[depr]](depr "Annex D (normative) Compatibility features"),
|
||
its meaning is established
|
||
as-if by performing unqualified name lookup ([[basic.lookup.unqual]](basic.lookup.unqual "6.5.3 Unqualified name lookup"))
|
||
in the context of D[.](#contents-3.sentence-1)
|
||
|
||
[*Note [1](#contents-note-1)*:
|
||
|
||
Argument-dependent lookup is not performed[.](#contents-3.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
Similarly, the meaning of a [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3 Qualified names [expr.prim.id.qual]") is established
|
||
as-if by performing qualified name lookup ([[basic.lookup.qual]](basic.lookup.qual "6.5.5 Qualified name lookup"))
|
||
in the context of D[.](#contents-3.sentence-3)
|
||
|
||
[*Example [1](#contents-example-1)*:
|
||
|
||
The reference to is_array_v in the specification of std::to_array ([[array.creation]](array.creation "23.3.3.6 Array creation functions")) refers to ::std::is_array_v[.](#contents-3.sentence-4)
|
||
|
||
â *end example*]
|
||
|
||
[*Note [2](#contents-note-2)*:
|
||
|
||
Operators in expressions ([[over.match.oper]](over.match.oper "12.2.2.3 Operators in expressions")) are not so constrained;
|
||
see [[global.functions]](#global.functions "16.4.6.4 Non-member functions")[.](#contents-3.sentence-5)
|
||
|
||
â *end note*]
|
||
|
||
The meaning of the unqualified name swap is established
|
||
in an overload resolution context
|
||
for swappable values ([[swappable.requirements]](#swappable.requirements "16.4.4.3 Swappable requirements"))[.](#contents-3.sentence-6)
|
||
|
||
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]](basic.lookup.argdep "6.5.4 Argument-dependent name lookup"))[.](#contents-3.sentence-7)
|
||
|
||
[142)](#footnote-142)[142)](#footnoteref-142)
|
||
|
||
The C standard library headers ([[support.c.headers]](support.c.headers "17.15 C headers")) also define
|
||
names within the global namespace, while the C++ headers for C library
|
||
facilities ([[headers]](#headers "16.4.2.3 Headers")) can also define names within the global namespace[.](#footnote-142.sentence-1)
|
||
|
||
[143)](#footnote-143)[143)](#footnoteref-143)
|
||
|
||
This gives implementers freedom to use inline namespaces to
|
||
support multiple configurations of the library[.](#footnote-143.sentence-1)
|
||
|
||
#### [16.4.2.3](#headers) Headers [[headers]](headers)
|
||
|
||
[1](#headers-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1182)
|
||
|
||
Each element of the C++ standard library is declared or defined (as appropriate) in a[*header*](#def:header "16.4.2.3 Headers [headers]")[.](#headers-1.sentence-1)[144](#footnote-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]).")
|
||
|
||
[2](#headers-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1191)
|
||
|
||
The C++ standard library provides the[*C++ library headers*](#def:header,C++_library "16.4.2.3 Headers [headers]"),
|
||
shown in Table [24](#tab:headers.cpp "Table 24: C++ library headers")[.](#headers-2.sentence-1)
|
||
|
||
Table [24](#tab:headers.cpp) — C++ library headers [[tab:headers.cpp]](./tab:headers.cpp)
|
||
|
||
| [ð](#tab:headers.cpp-row-1)<br><algorithm> | <forward_list> | <meta> | <stack> |
|
||
| --- | --- | --- | --- |
|
||
| [ð](#tab:headers.cpp-row-2)<br><any> | <fstream> | <mutex> | <stacktrace> |
|
||
| [ð](#tab:headers.cpp-row-3)<br><array> | <functional> | <new> | <stdexcept> |
|
||
| [ð](#tab:headers.cpp-row-4)<br><atomic> | <future> | <numbers> | <stdfloat> |
|
||
| [ð](#tab:headers.cpp-row-5)<br><barrier> | <generator> | <numeric> | <stop_token> |
|
||
| [ð](#tab:headers.cpp-row-6)<br><bit> | <hazard_pointer> | <optional> | <streambuf> |
|
||
| [ð](#tab:headers.cpp-row-7)<br><bitset> | <hive> | <ostream> | <string> |
|
||
| [ð](#tab:headers.cpp-row-8)<br><charconv> | <initializer_list> | <print> | <string_view> |
|
||
| [ð](#tab:headers.cpp-row-9)<br><chrono> | <inplace_vector> | <queue> | <syncstream> |
|
||
| [ð](#tab:headers.cpp-row-10)<br><compare> | <iomanip> | <random> | <system_error> |
|
||
| [ð](#tab:headers.cpp-row-11)<br><complex> | <ios> | <ranges> | <text_encoding> |
|
||
| [ð](#tab:headers.cpp-row-12)<br><concepts> | <iosfwd> | <ratio> | <thread> |
|
||
| [ð](#tab:headers.cpp-row-13)<br><condition_variable> | <iostream> | <rcu> | <tuple> |
|
||
| [ð](#tab:headers.cpp-row-14)<br><contracts> | <istream> | <regex> | <type_traits> |
|
||
| [ð](#tab:headers.cpp-row-15)<br><coroutine> | <iterator> | <scoped_allocator> | <typeindex> |
|
||
| [ð](#tab:headers.cpp-row-16)<br><debugging> | <latch> | <semaphore> | <typeinfo> |
|
||
| [ð](#tab:headers.cpp-row-17)<br><deque> | <limits> | <set> | <unordered_map> |
|
||
| [ð](#tab:headers.cpp-row-18)<br><exception> | <linalg> | <shared_mutex> | <unordered_set> |
|
||
| [ð](#tab:headers.cpp-row-19)<br><execution> | <list> | <simd> | <utility> |
|
||
| [ð](#tab:headers.cpp-row-20)<br><expected> | <locale> | <source_location> | <valarray> |
|
||
| [ð](#tab:headers.cpp-row-21)<br><filesystem> | <map> | <span> | <variant> |
|
||
| [ð](#tab:headers.cpp-row-22)<br><flat_map> | <mdspan> | <spanstream> | <vector> |
|
||
| [ð](#tab:headers.cpp-row-23)<br><flat_set> | <memory> | <sstream> | <version> |
|
||
| [ð](#tab:headers.cpp-row-24)<br><format> | <memory_resource> | | |
|
||
|
||
[3](#headers-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1297)
|
||
|
||
The facilities of the C standard library are provided in theadditional headers shown in Table [25](#tab:headers.cpp.c "Table 25: C++ headers for C library facilities")[.](#headers-3.sentence-1)[145](#footnote-145 "It is intentional that there is no C++ header for any of these C headers: <stdnoreturn.h>, <threads.h>.")
|
||
|
||
Table [25](#tab:headers.cpp.c) — C++ headers for C library facilities [[tab:headers.cpp.c]](./tab:headers.cpp.c)
|
||
|
||
| [ð](#tab:headers.cpp.c-row-1)<br><cassert> | <cfenv> | <climits> | <csetjmp> | <cstddef> | <cstdlib> | <cuchar> |
|
||
| --- | --- | --- | --- | --- | --- | --- |
|
||
| [ð](#tab:headers.cpp.c-row-2)<br><cctype> | <cfloat> | <clocale> | <csignal> | <cstdint> | <cstring> | <cwchar> |
|
||
| [ð](#tab:headers.cpp.c-row-3)<br><cerrno> | <cinttypes> | <cmath> | <cstdarg> | <cstdio> | <ctime> | <cwctype> |
|
||
|
||
[4](#headers-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1339)
|
||
|
||
The headers listed in Table [24](#tab:headers.cpp "Table 24: C++ library headers"), 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*](#def:C++_library_headers,importable "16.4.2.3 Headers [headers]")[.](#headers-4.sentence-1)
|
||
|
||
[*Note [1](#headers-note-1)*:
|
||
|
||
Importable C++ library headers can be
|
||
imported ([[module.import]](module.import "10.3 Import declaration"))[.](#headers-4.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
[*Example [1](#headers-example-1)*: import <vector>; // imports the <vector> header unit std::vector<int> vi; // OK â *end example*]
|
||
|
||
[5](#headers-5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1356)
|
||
|
||
Except as noted in [[library]](library "16 Library introduction") through [[exec]](exec "33 Execution control library") and [[depr]](depr "Annex D (normative) Compatibility features"), the contents of each header c*name* is
|
||
the same as that of the corresponding header *name*.h as
|
||
specified in the [C standard library](intro.refs#def:C,standard_library "2 Normative references [intro.refs]")[.](#headers-5.sentence-1)
|
||
|
||
In the C++ standard library, however, the
|
||
declarations (except for names which are defined as macros in C) are within[namespace scope](basic.scope.namespace "6.4.6 Namespace scope [basic.scope.namespace]") of the namespace std[.](#headers-5.sentence-2)
|
||
|
||
It is unspecified whether these names (including any overloads added in[[support]](support "17 Language support library") through [[exec]](exec "33 Execution control library") and [[depr]](depr "Annex D (normative) Compatibility features"))
|
||
are first declared within the global namespace scope
|
||
and are then injected into namespace std by explicit[*using-declaration*](namespace.udecl#nt:using-declaration "9.10 The using declaration [namespace.udecl]")*s* ([[namespace.udecl]](namespace.udecl "9.10 The using declaration"))[.](#headers-5.sentence-3)
|
||
|
||
[6](#headers-6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1370)
|
||
|
||
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[.](#headers-6.sentence-1)
|
||
|
||
[*Note [2](#headers-note-2)*:
|
||
|
||
The names defined as macros in C include the following:assert, offsetof, setjmp, va_arg,va_end, and va_start[.](#headers-6.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
[7](#headers-7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1379)
|
||
|
||
Names that are defined as functions in C shall be defined as functions in the
|
||
C++ standard library[.](#headers-7.sentence-1)[146](#footnote-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.")
|
||
|
||
[8](#headers-8)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1389)
|
||
|
||
Identifiers that are keywords or operators in C++ shall not be defined as
|
||
macros in C++ standard library headers[.](#headers-8.sentence-1)[147](#footnote-147 "In particular, including the standard header <iso646.h> has no effect.")
|
||
|
||
[9](#headers-9)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1397)
|
||
|
||
Subclause [[support.c.headers]](support.c.headers "17.15 C headers") describes the effects of using
|
||
the *name*.h (C header) form in a C++ program[.](#headers-9.sentence-1)[148](#footnote-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.")
|
||
|
||
[10](#headers-10)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1408)
|
||
|
||
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[.](#headers-10.sentence-1)
|
||
|
||
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[.](#headers-10.sentence-2)
|
||
|
||
If any C++ header is included,
|
||
it is implementation-defined
|
||
whether any of these names
|
||
is declared in the global namespace[.](#headers-10.sentence-3)
|
||
|
||
(None of them is declared in namespace std[.](#headers-10.sentence-4))
|
||
|
||
[11](#headers-11)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1425)
|
||
|
||
Table [26](#tab:c.annex.k.names "Table 26: Names from ISO/IEC 9899:2024, Annex K") lists the Annex K names
|
||
that may be declared in some header[.](#headers-11.sentence-1)
|
||
|
||
These names are also subject to the restrictions of [[macro.names]](#macro.names "16.4.5.3.3 Macro names")[.](#headers-11.sentence-2)
|
||
|
||
Table [26](#tab:c.annex.k.names) — Names from ISO/IEC 9899:2024, Annex K [[tab:c.annex.k.names]](./tab:c.annex.k.names)
|
||
|
||
| [ð](#tab:c.annex.k.names-row-1)<br>abort_handler_s | mbstowcs_s | strncat_s | vswscanf_s |
|
||
| --- | --- | --- | --- |
|
||
| [ð](#tab:c.annex.k.names-row-2)<br>asctime_s | memcpy_s | strncpy_s | vwprintf_s |
|
||
| [ð](#tab:c.annex.k.names-row-3)<br>bsearch_s | memmove_s | strtok_s | vwscanf_s |
|
||
| [ð](#tab:c.annex.k.names-row-4)<br>constraint_handler_t | memset_s | swprintf_s | wcrtomb_s |
|
||
| [ð](#tab:c.annex.k.names-row-5)<br>ctime_s | printf_s | swscanf_s | wcscat_s |
|
||
| [ð](#tab:c.annex.k.names-row-6)<br>errno_t | qsort_s | tmpfile_s | wcscpy_s |
|
||
| [ð](#tab:c.annex.k.names-row-7)<br>fopen_s | RSIZE_MAX | TMP_MAX_S | wcsncat_s |
|
||
| [ð](#tab:c.annex.k.names-row-8)<br>fprintf_s | rsize_t | tmpnam_s | wcsncpy_s |
|
||
| [ð](#tab:c.annex.k.names-row-9)<br>freopen_s | scanf_s | vfprintf_s | wcsnlen_s |
|
||
| [ð](#tab:c.annex.k.names-row-10)<br>fscanf_s | set_constraint_handler_s | vfscanf_s | wcsrtombs_s |
|
||
| [ð](#tab:c.annex.k.names-row-11)<br>fwprintf_s | snprintf_s | vfwprintf_s | wcstok_s |
|
||
| [ð](#tab:c.annex.k.names-row-12)<br>fwscanf_s | snwprintf_s | vfwscanf_s | wcstombs_s |
|
||
| [ð](#tab:c.annex.k.names-row-13)<br>getenv_s | sprintf_s | vprintf_s | wctomb_s |
|
||
| [ð](#tab:c.annex.k.names-row-14)<br>gets_s | sscanf_s | vscanf_s | wmemcpy_s |
|
||
| [ð](#tab:c.annex.k.names-row-15)<br>gmtime_s | strcat_s | vsnprintf_s | wmemmove_s |
|
||
| [ð](#tab:c.annex.k.names-row-16)<br>ignore_handler_s | strcpy_s | vsnwprintf_s | wprintf_s |
|
||
| [ð](#tab:c.annex.k.names-row-17)<br>localtime_s | strerrorlen_s | vsprintf_s | wscanf_s |
|
||
| [ð](#tab:c.annex.k.names-row-18)<br>L_tmpnam_s | strerror_s | vsscanf_s | |
|
||
| [ð](#tab:c.annex.k.names-row-19)<br>mbsrtowcs_s | strlen_s | vswprintf_s | |
|
||
|
||
[144)](#footnote-144)[144)](#footnoteref-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]](cpp.include "15.3 Source file inclusion"))[.](#footnote-144.sentence-1)
|
||
|
||
[145)](#footnote-145)[145)](#footnoteref-145)
|
||
|
||
It is intentional that there is no C++ header
|
||
for any of these C headers:<stdnoreturn.h>,<threads.h>[.](#footnote-145.sentence-1)
|
||
|
||
[146)](#footnote-146)[146)](#footnoteref-146)
|
||
|
||
This disallows the practice, allowed in C, of
|
||
providing a masking macro in addition to the function prototype[.](#footnote-146.sentence-1)
|
||
|
||
The only way to
|
||
achieve equivalent inline behavior in C++ is to provide a definition as an
|
||
extern inline function[.](#footnote-146.sentence-2)
|
||
|
||
[147)](#footnote-147)[147)](#footnoteref-147)
|
||
|
||
In particular, including the
|
||
standard header [<iso646.h>](iso646.h.syn#header:%3ciso646.h%3e "17.15.3 Header <iso646.h> synopsis [iso646.h.syn]") has no effect[.](#footnote-147.sentence-1)
|
||
|
||
[148)](#footnote-148)[148)](#footnoteref-148)
|
||
|
||
The".h" headers dump all their names into the global namespace, whereas the
|
||
newer forms keep their names in namespace std[.](#footnote-148.sentence-1)
|
||
|
||
Therefore, the newer
|
||
forms are the preferred forms for all uses except for C++ programs which are
|
||
intended to be strictly compatible with C[.](#footnote-148.sentence-2)
|
||
|
||
#### [16.4.2.4](#std.modules) Modules [[std.modules]](std.modules)
|
||
|
||
[1](#std.modules-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1513)
|
||
|
||
The C++ standard library provides
|
||
the following [*C++ library modules*](#def:C++_library_modules "16.4.2.4 Modules [std.modules]")[.](#std.modules-1.sentence-1)
|
||
|
||
[2](#std.modules-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1517)
|
||
|
||
The named module std exports declarations in namespace std that are provided by the importable C++ library headers
|
||
(Table [24](#tab:headers.cpp "Table 24: C++ library headers") or the subset provided by a freestanding implementation)
|
||
and the C++ headers for C library facilities (Table [25](#tab:headers.cpp.c "Table 25: C++ headers for C library facilities"))[.](#std.modules-2.sentence-1)
|
||
|
||
It additionally exports declarations in the global namespace
|
||
for the storage allocation and deallocation functions
|
||
that are provided by [<new>](support.dynamic.general#header:%3cnew%3e "17.6.1 General [support.dynamic.general]")[.](#std.modules-2.sentence-2)
|
||
|
||
[3](#std.modules-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1526)
|
||
|
||
The named module std.compat exports the same declarations as
|
||
the named module std, and
|
||
additionally exports
|
||
|
||
- [(3.1)](#std.modules-3.1)
|
||
|
||
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](#tab:headers.cpp.c "Table 25: C++ headers for C library facilities")),
|
||
except the explicitly excluded declarations
|
||
described in [[support.c.headers.other]](support.c.headers.other "17.15.7 Other C headers") and
|
||
|
||
- [(3.2)](#std.modules-3.2)
|
||
|
||
declarations provided by
|
||
the headers [<stdbit.h>](stdbit.h.syn#header:%3cstdbit.h%3e "22.12 Header <stdbit.h> synopsis [stdbit.h.syn]") and [<stdckdint.h>](stdckdint.h.syn#header:%3cstdckdint.h%3e "29.11.1 Header <stdckdint.h> synopsis [stdckdint.h.syn]")[.](#std.modules-3.sentence-1)
|
||
|
||
[4](#std.modules-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1543)
|
||
|
||
It is unspecified to which module a declaration in the standard library
|
||
is attached[.](#std.modules-4.sentence-1)
|
||
|
||
[*Note [1](#std.modules-note-1)*:
|
||
|
||
Conforming implementations ensure that mixing#include and import does not result in
|
||
conflicting attachments ([[basic.link]](basic.link "6.7 Program and linkage"))[.](#std.modules-4.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
*Recommended practice*: Implementations should ensure such attachments do not preclude
|
||
further evolution or decomposition of the standard library modules[.](#std.modules-4.sentence-3)
|
||
|
||
[5](#std.modules-5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1555)
|
||
|
||
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[.](#std.modules-5.sentence-1)
|
||
|
||
[6](#std.modules-6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1562)
|
||
|
||
*Recommended practice*: Implementations should avoid exporting any other declarations
|
||
from the C++ library modules[.](#std.modules-6.sentence-1)
|
||
|
||
[*Note [2](#std.modules-note-2)*:
|
||
|
||
Like all named modules, the C++ library modules
|
||
do not make macros visible ([[module.import]](module.import "10.3 Import declaration")), such asassert ([[cassert.syn]](cassert.syn "19.3.2 Header <cassert> synopsis")),errno ([[cerrno.syn]](cerrno.syn "19.4.2 Header <cerrno> synopsis")),offsetof ([[cstddef.syn]](cstddef.syn "17.2.1 Header <cstddef> synopsis")), andva_arg ([[cstdarg.syn]](cstdarg.syn "17.14.2 Header <cstdarg> synopsis"))[.](#std.modules-6.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
#### [16.4.2.5](#compliance) Freestanding implementations [[compliance]](compliance)
|
||
|
||
[1](#compliance-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1579)
|
||
|
||
Two kinds of implementations are defined:hosted and freestanding ([[intro.compliance]](intro.compliance "4.1 Implementation compliance"));
|
||
the kind of the implementation isimplementation-defined[.](#compliance-1.sentence-1)
|
||
|
||
For a hosted implementation, this document
|
||
describes the set of available headers[.](#compliance-1.sentence-2)
|
||
|
||
[2](#compliance-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1588)
|
||
|
||
A freestanding implementation has animplementation-defined set of headers[.](#compliance-2.sentence-1)
|
||
|
||
This set shall
|
||
include at least the headers shown in Table [27](#tab:headers.cpp.fs "Table 27: C++ headers for freestanding implementations")[.](#compliance-2.sentence-2)
|
||
|
||
Table [27](#tab:headers.cpp.fs) — C++ headers for freestanding implementations [[tab:headers.cpp.fs]](./tab:headers.cpp.fs)
|
||
|
||
| [ð](#tab:headers.cpp.fs-row-1) | **Subclause** | **Header** |
|
||
| --- | --- | --- |
|
||
| [ð](#tab:headers.cpp.fs-row-2)<br>[[support.types]](support.types "17.2 Common definitions") | Common definitions | <cstddef> |
|
||
| [ð](#tab:headers.cpp.fs-row-3)<br>[[cstdlib.syn]](cstdlib.syn "17.2.2 Header <cstdlib> synopsis") | C standard library | <cstdlib> |
|
||
| [ð](#tab:headers.cpp.fs-row-4)<br>[[support.limits]](support.limits "17.3 Implementation properties") | Implementation properties | <cfloat>, <climits>, <limits>, |
|
||
| [ð](#tab:headers.cpp.fs-row-5) | | <version> |
|
||
| [ð](#tab:headers.cpp.fs-row-6)<br>[[cstdint.syn]](cstdint.syn "17.4.1 Header <cstdint> synopsis") | Integer types | <cstdint> |
|
||
| [ð](#tab:headers.cpp.fs-row-7)<br>[[support.dynamic]](support.dynamic "17.6 Dynamic memory management") | Dynamic memory management | <new> |
|
||
| [ð](#tab:headers.cpp.fs-row-8)<br>[[support.rtti]](support.rtti "17.7 Type identification") | Type identification | <typeinfo> |
|
||
| [ð](#tab:headers.cpp.fs-row-9)<br>[[support.srcloc]](support.srcloc "17.8 Source location") | Source location | <source_location> |
|
||
| [ð](#tab:headers.cpp.fs-row-10)<br>[[support.exception]](support.exception "17.9 Exception handling") | Exception handling | <exception> |
|
||
| [ð](#tab:headers.cpp.fs-row-11)<br>[[support.initlist]](support.initlist "17.11 Initializer lists") | Initializer lists | <initializer_list> |
|
||
| [ð](#tab:headers.cpp.fs-row-12)<br>[[cmp]](cmp "17.12 Comparisons") | Comparisons | <compare> |
|
||
| [ð](#tab:headers.cpp.fs-row-13)<br>[[support.contract]](support.contract "17.10 Contract-violation handling") | Contract-violation handling | <contracts> |
|
||
| [ð](#tab:headers.cpp.fs-row-14)<br>[[support.coroutine]](support.coroutine "17.13 Coroutines") | Coroutines support | <coroutine> |
|
||
| [ð](#tab:headers.cpp.fs-row-15)<br>[[support.runtime]](support.runtime "17.14 Other runtime support") | Other runtime support | <cstdarg> |
|
||
| [ð](#tab:headers.cpp.fs-row-16)<br>[[concepts]](concepts "18 Concepts library") | Concepts library | <concepts> |
|
||
| [ð](#tab:headers.cpp.fs-row-17)<br>[[errno]](errno "19.4 Error numbers") | Error numbers | <cerrno> |
|
||
| [ð](#tab:headers.cpp.fs-row-18)<br>[[syserr]](syserr "19.5 System error support") | System error support | <system_error> |
|
||
| [ð](#tab:headers.cpp.fs-row-19)<br>[[debugging]](debugging "19.7 Debugging") | Debugging | <debugging> |
|
||
| [ð](#tab:headers.cpp.fs-row-20)<br>[[memory]](memory "20.2 Memory") | Memory | <memory> |
|
||
| [ð](#tab:headers.cpp.fs-row-21)<br>[[type.traits]](type.traits "21.3 Metaprogramming and type traits") | Type traits | <type_traits> |
|
||
| [ð](#tab:headers.cpp.fs-row-22)<br>[[ratio]](ratio "21.5 Compile-time rational arithmetic") | Compile-time rational arithmetic | <ratio> |
|
||
| [ð](#tab:headers.cpp.fs-row-23)<br>[[utility]](utility "22.2 Utility components") | Utility components | <utility> |
|
||
| [ð](#tab:headers.cpp.fs-row-24)<br>[[tuple]](tuple "22.4 Tuples") | Tuples | <tuple> |
|
||
| [ð](#tab:headers.cpp.fs-row-25)<br>[[optional]](optional "22.5 Optional objects") | Optional objects | <optional> |
|
||
| [ð](#tab:headers.cpp.fs-row-26)<br>[[variant]](variant "22.6 Variants") | Variants | <variant> |
|
||
| [ð](#tab:headers.cpp.fs-row-27)<br>[[expected]](expected "22.8 Expected objects") | Expected objects | <expected> |
|
||
| [ð](#tab:headers.cpp.fs-row-28)<br>[[function.objects]](function.objects "22.10 Function objects") | Function objects | <functional> |
|
||
| [ð](#tab:headers.cpp.fs-row-29)<br>[[bit]](bit "22.11 Bit manipulation") | Bit manipulation | <bit> |
|
||
| [ð](#tab:headers.cpp.fs-row-30)<br>[[stdbit.h.syn]](stdbit.h.syn "22.12 Header <stdbit.h> synopsis") | C-compatible bit manipulation | <stdbit.h> |
|
||
| [ð](#tab:headers.cpp.fs-row-31)<br>[[array]](array "23.3.3 Class template array") | Class template array | <array> |
|
||
| [ð](#tab:headers.cpp.fs-row-32)<br>[[inplace.vector]](inplace.vector "23.3.16 Class template inplace_vector") | Class template inplace_vector | <inplace_vector> |
|
||
| [ð](#tab:headers.cpp.fs-row-33)<br>[[views.contiguous]](views.contiguous "23.7.2 Contiguous access") | Contiguous access | <span> |
|
||
| [ð](#tab:headers.cpp.fs-row-34)<br>[[views.multidim]](views.multidim "23.7.3 Multidimensional access") | Multidimensional access | <mdspan> |
|
||
| [ð](#tab:headers.cpp.fs-row-35)<br>[[iterators]](iterators "24 Iterators library") | Iterators library | <iterator> |
|
||
| [ð](#tab:headers.cpp.fs-row-36)<br>[[ranges]](ranges "25 Ranges library") | Ranges library | <ranges> |
|
||
| [ð](#tab:headers.cpp.fs-row-37)<br>[[algorithms]](algorithms "26 Algorithms library") | Algorithms library | <algorithm>, <numeric> |
|
||
| [ð](#tab:headers.cpp.fs-row-38)<br>[[execpol]](execpol "26.3.6 Execution policies") | Execution policies | <execution> |
|
||
| [ð](#tab:headers.cpp.fs-row-39)<br>[[string.view]](string.view "27.3 String view classes") | String view classes | <string_view> |
|
||
| [ð](#tab:headers.cpp.fs-row-40)<br>[[string.classes]](string.classes "27.4 String classes") | String classes | <string> |
|
||
| [ð](#tab:headers.cpp.fs-row-41)<br>[[c.strings]](c.strings "27.5 Null-terminated sequence utilities") | Null-terminated sequence utilities | <cstring>, <cwchar> |
|
||
| [ð](#tab:headers.cpp.fs-row-42)<br>[[charconv]](charconv "28.2 Primitive numeric conversions") | Primitive numeric conversions | <charconv> |
|
||
| [ð](#tab:headers.cpp.fs-row-43)<br>[[rand]](rand "29.5 Random number generation") | Random number generation | <random> |
|
||
| [ð](#tab:headers.cpp.fs-row-44)<br>[[c.math]](c.math "29.7 Mathematical functions for floating-point types") | Mathematical functions for floating-point types | <cmath> |
|
||
| [ð](#tab:headers.cpp.fs-row-45)<br>[[atomics]](atomics "32.5 Atomic operations") | Atomics | <atomic> |
|
||
| [ð](#tab:headers.cpp.fs-row-46) |
|
||
|
||
[3](#compliance-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1641)
|
||
|
||
For each of the headers listed in Table [27](#tab:headers.cpp.fs "Table 27: C++ headers for freestanding implementations"),
|
||
a freestanding implementation provides at least
|
||
the freestanding items ([[freestanding.item]](freestanding.item "16.3.3.7 Freestanding items")) declared in the header[.](#compliance-3.sentence-1)
|
||
|
||
[4](#compliance-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1646)
|
||
|
||
The [*hosted library facilities*](#def:library_facilities,hosted "16.4.2.5 Freestanding implementations [compliance]") are
|
||
the set of facilities described in this document
|
||
that are required for hosted implementations,
|
||
but not required for freestanding implementations[.](#compliance-4.sentence-1)
|
||
|
||
A freestanding implementation provides
|
||
a (possibly empty) implementation-defined subset of
|
||
the hosted library facilities[.](#compliance-4.sentence-2)
|
||
|
||
Unless otherwise specified, the requirements on
|
||
each declaration, entity, [*typedef-name*](dcl.typedef#nt:typedef-name "9.2.4 The typedef specifier [dcl.typedef]"), 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[.](#compliance-4.sentence-3)
|
||
|
||
[5](#compliance-5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1660)
|
||
|
||
A freestanding implementation provides
|
||
deleted definitions ([[dcl.fct.def.delete]](dcl.fct.def.delete "9.6.3 Deleted definitions")) for
|
||
a (possibly empty) implementation-defined subset of
|
||
the namespace-scope functions and function templates
|
||
from the hosted library facilities[.](#compliance-5.sentence-1)
|
||
|
||
[*Note [1](#compliance-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[.](#compliance-5.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
### [16.4.3](#using) Using the library [[using]](using)
|
||
|
||
#### [16.4.3.1](#using.overview) Overview [[using.overview]](using.overview)
|
||
|
||
[1](#using.overview-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1678)
|
||
|
||
Subclause [[using]](#using "16.4.3 Using the library") describes how a C++ program gains access to the facilities of the
|
||
C++ standard library[.](#using.overview-1.sentence-1)
|
||
|
||
[[using.headers]](#using.headers "16.4.3.2 Headers") describes effects during translation
|
||
phase 4, while [[using.linkage]](#using.linkage "16.4.3.3 Linkage") describes effects during [phase
|
||
8](lex.phases "5.2 Phases of translation [lex.phases]")[.](#using.overview-1.sentence-2)
|
||
|
||
#### [16.4.3.2](#using.headers) Headers [[using.headers]](using.headers)
|
||
|
||
[1](#using.headers-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1686)
|
||
|
||
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]](cpp.include "15.3 Source file inclusion"))
|
||
or the appropriateimport declaration ([[module.import]](module.import "10.3 Import declaration"))[.](#using.headers-1.sentence-1)
|
||
|
||
[2](#using.headers-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1698)
|
||
|
||
A translation unit may include library headers in any order ([[lex.separate]](lex.separate "5.1 Separate translation"))[.](#using.headers-2.sentence-1)
|
||
|
||
Each may be included more than once, with no effect different from
|
||
being included exactly once, except that the effect of including either[<cassert>](assertions.general#header:%3ccassert%3e "19.3.1 General [assertions.general]") or [<assert.h>](support.c.headers.general#header:%3cassert.h%3e "17.15.1 General [support.c.headers.general]") depends each time on the lexically current definition ofNDEBUG[.](#using.headers-2.sentence-2)[149](#footnote-149 "This is the same as the C standard library.")
|
||
|
||
[3](#using.headers-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1712)
|
||
|
||
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*](module.global.frag#nt:global-module-fragment "10.4 Global module fragment [module.global.frag]"), 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[.](#using.headers-3.sentence-1)
|
||
|
||
No diagnostic is required[.](#using.headers-3.sentence-2)
|
||
|
||
[149)](#footnote-149)[149)](#footnoteref-149)
|
||
|
||
This is the same as the C standard library[.](#footnote-149.sentence-1)
|
||
|
||
#### [16.4.3.3](#using.linkage) Linkage [[using.linkage]](using.linkage)
|
||
|
||
[1](#using.linkage-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1724)
|
||
|
||
Entities in the C++ standard library have [external linkage](basic.link "6.7 Program and linkage [basic.link]")[.](#using.linkage-1.sentence-1)
|
||
|
||
Unless otherwise specified, objects and functions have the defaultextern "C++" linkage ([[dcl.link]](dcl.link "9.12 Linkage specifications"))[.](#using.linkage-1.sentence-2)
|
||
|
||
[2](#using.linkage-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1730)
|
||
|
||
Whether a name from the C standard library declared with
|
||
external linkage hasextern "C" orextern "C++" linkage is implementation-defined[.](#using.linkage-2.sentence-1)
|
||
|
||
It is recommended that an
|
||
implementation useextern "C++" linkage for this purpose[.](#using.linkage-2.sentence-2)[150](#footnote-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.")
|
||
|
||
[3](#using.linkage-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1751)
|
||
|
||
Objects and functions
|
||
defined in the library and required by a C++ program are included in
|
||
the program prior to program startup[.](#using.linkage-3.sentence-1)
|
||
|
||
[4](#using.linkage-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1757)
|
||
|
||
See also[replacement functions](#replacement.functions "16.4.5.6 Replacement functions [replacement.functions]"),[runtime changes](#handler.functions "16.4.5.7 Handler functions [handler.functions]")[.](#using.linkage-4.sentence-1)
|
||
|
||
[150)](#footnote-150)[150)](#footnoteref-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[.](#footnote-150.sentence-1)
|
||
|
||
### [16.4.4](#utility.requirements) Requirements on types and expressions [[utility.requirements]](utility.requirements)
|
||
|
||
#### [16.4.4.1](#utility.requirements.general) General [[utility.requirements.general]](utility.requirements.general)
|
||
|
||
[1](#utility.requirements.general-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1766)
|
||
|
||
[[utility.arg.requirements]](#utility.arg.requirements "16.4.4.2 Template argument requirements") describes requirements on types and expressions used to instantiate templates
|
||
defined in the C++ standard library[.](#utility.requirements.general-1.sentence-1)
|
||
|
||
[[swappable.requirements]](#swappable.requirements "16.4.4.3 Swappable requirements") describes the requirements on swappable types and
|
||
swappable expressions[.](#utility.requirements.general-1.sentence-2)
|
||
|
||
[[nullablepointer.requirements]](#nullablepointer.requirements "16.4.4.4 Cpp17NullablePointer requirements") describes the requirements on pointer-like
|
||
types that support null values[.](#utility.requirements.general-1.sentence-3)
|
||
|
||
[[hash.requirements]](#hash.requirements "16.4.4.5 Cpp17Hash requirements") describes the requirements on hash function objects[.](#utility.requirements.general-1.sentence-4)
|
||
|
||
[[allocator.requirements]](#allocator.requirements "16.4.4.6 Cpp17Allocator requirements") describes the requirements on storage
|
||
allocators[.](#utility.requirements.general-1.sentence-5)
|
||
|
||
#### [16.4.4.2](#utility.arg.requirements) Template argument requirements [[utility.arg.requirements]](utility.arg.requirements)
|
||
|
||
[1](#utility.arg.requirements-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1780)
|
||
|
||
The template definitions in the C++ standard library
|
||
refer to various named requirements whose details are set out in
|
||
Tables [28](#tab:cpp17.equalitycomparable "Table 28: Cpp17EqualityComparable requirements")â[35](#tab:cpp17.destructible "Table 35: Cpp17Destructible requirements")[.](#utility.arg.requirements-1.sentence-1)
|
||
|
||
In these tables,
|
||
|
||
- [(1.1)](#utility.arg.requirements-1.1)
|
||
|
||
T denotes an object or reference type to be
|
||
supplied by a C++ program instantiating a template,
|
||
|
||
- [(1.2)](#utility.arg.requirements-1.2)
|
||
|
||
a,b, andc denote values of type (possibly const) T,
|
||
|
||
- [(1.3)](#utility.arg.requirements-1.3)
|
||
|
||
s and t denote modifiable lvalues of type T,
|
||
|
||
- [(1.4)](#utility.arg.requirements-1.4)
|
||
|
||
u denotes an identifier,
|
||
|
||
- [(1.5)](#utility.arg.requirements-1.5)
|
||
|
||
rv denotes an rvalue of type T, and
|
||
|
||
- [(1.6)](#utility.arg.requirements-1.6)
|
||
|
||
v denotes an lvalue of type (possibly const) T or an
|
||
rvalue of type const T[.](#utility.arg.requirements-1.sentence-2)
|
||
|
||
[2](#utility.arg.requirements-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1804)
|
||
|
||
In general, a default constructor is not required[.](#utility.arg.requirements-2.sentence-1)
|
||
|
||
Certain container class
|
||
member function signatures specify T() as a default argument[.](#utility.arg.requirements-2.sentence-2)
|
||
|
||
T() shall be a well-defined expression ([[dcl.init]](dcl.init "9.5 Initializers")) if one of those
|
||
signatures is called using the [default argument](dcl.fct.default "9.3.4.7 Default arguments [dcl.fct.default]")[.](#utility.arg.requirements-2.sentence-3)
|
||
|
||
Table [28](#tab:cpp17.equalitycomparable) — *Cpp17EqualityComparable* requirements [[tab:cpp17.equalitycomparable]](./tab:cpp17.equalitycomparable)
|
||
|
||
| [ð](#tab:cpp17.equalitycomparable-row-1)<br>**Expression** | **Return type** | **Requirement** |
|
||
| --- | --- | --- |
|
||
| [ð](#tab:cpp17.equalitycomparable-row-2)<br>a == b | decltype(a == b) models *boolean-testable* | == is an equivalence relation, that is, it has the following properties: <br> <br>For all a, a == a[.](#tab:cpp17.equalitycomparable-row-2-column-3-sentence-1)<br> If a == b, then b == a[.](#tab:cpp17.equalitycomparable-row-2-column-3-sentence-1)<br> If a == b and b == c, then a == c[.](#tab:cpp17.equalitycomparable-row-2-column-3-sentence-1) |
|
||
|
||
Table [29](#tab:cpp17.lessthancomparable) — *Cpp17LessThanComparable* requirements [[tab:cpp17.lessthancomparable]](./tab:cpp17.lessthancomparable)
|
||
|
||
| [ð](#tab:cpp17.lessthancomparable-row-1)<br>**Expression** | **Return type** | **Requirement** |
|
||
| --- | --- | --- |
|
||
| [ð](#tab:cpp17.lessthancomparable-row-2)<br>a < b | decltype(a < b) models *boolean-testable* | < is a strict weak ordering relation ([[alg.sorting]](alg.sorting "26.8 Sorting and related operations")) |
|
||
|
||
Table [30](#tab:cpp17.defaultconstructible) — *Cpp17DefaultConstructible* requirements [[tab:cpp17.defaultconstructible]](./tab:cpp17.defaultconstructible)
|
||
|
||
| [ð](#tab:cpp17.defaultconstructible-row-1)<br>**Expression** | **Post-condition** |
|
||
| --- | --- |
|
||
| [ð](#tab:cpp17.defaultconstructible-row-2)<br>T t; | object t is default-initialized |
|
||
| [ð](#tab:cpp17.defaultconstructible-row-3)<br>T u{}; | object u is value-initialized or aggregate-initialized |
|
||
| [ð](#tab:cpp17.defaultconstructible-row-4)<br>T() T{} | an object of type T is value-initialized or aggregate-initialized |
|
||
|
||
Table [31](#tab:cpp17.moveconstructible) — *Cpp17MoveConstructible* requirements [[tab:cpp17.moveconstructible]](./tab:cpp17.moveconstructible)
|
||
|
||
| [ð](#tab:cpp17.moveconstructible-row-1)<br>**Expression** | **Post-condition** |
|
||
| --- | --- |
|
||
| [ð](#tab:cpp17.moveconstructible-row-2)<br>T u = rv; | u is equivalent to the value of rv before the construction |
|
||
| [ð](#tab:cpp17.moveconstructible-row-3)<br>T(rv) | T(rv) is equivalent to the value of rv before the construction |
|
||
| [ð](#tab:cpp17.moveconstructible-row-4)<br>rv's state is unspecified <br>[*Note [1](#tab:cpp17.moveconstructible-row-4-column-1-note-1)*:<br>rv must still meet the requirements of the library component that is using it[.](#tab:cpp17.moveconstructible-row-4-column-1-sentence-1)<br>The operations listed in those requirements must work as specified whether rv has been moved from or not[.](#tab:cpp17.moveconstructible-row-4-column-1-sentence-2) â *end note*] | |
|
||
|
||
Table [32](#tab:cpp17.copyconstructible) — *Cpp17CopyConstructible* requirements (in addition to [*Cpp17MoveConstructible*](#:Cpp17MoveConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]")) [[tab:cpp17.copyconstructible]](./tab:cpp17.copyconstructible)
|
||
|
||
| [ð](#tab:cpp17.copyconstructible-row-1)<br>**Expression** | **Post-condition** |
|
||
| --- | --- |
|
||
| [ð](#tab:cpp17.copyconstructible-row-2)<br>T u = v; | the value of v is unchanged and is equivalent to u |
|
||
| [ð](#tab:cpp17.copyconstructible-row-3)<br>T(v) | the value of v is unchanged and is equivalent to T(v) |
|
||
|
||
Table [33](#tab:cpp17.moveassignable) — *Cpp17MoveAssignable* requirements [[tab:cpp17.moveassignable]](./tab:cpp17.moveassignable)
|
||
|
||
| [ð](#tab:cpp17.moveassignable-row-1)<br>**Expression** | **Return type** | **Return value** | **Post-condition** |
|
||
| --- | --- | --- | --- |
|
||
| [ð](#tab:cpp17.moveassignable-row-2)<br>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 |
|
||
| [ð](#tab:cpp17.moveassignable-row-3)<br>rv's state is unspecified[.](#tab:cpp17.moveassignable-row-3-column-1-sentence-1)<br>[*Note [2](#tab:cpp17.moveassignable-row-3-column-1-note-2)*:<br>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[.](#tab:cpp17.moveassignable-row-3-column-1-sentence-2)<br>The operations listed in those requirements must work as specified whether rv has been moved from or not[.](#tab:cpp17.moveassignable-row-3-column-1-sentence-3) â *end note*] | | | |
|
||
|
||
Table [34](#tab:cpp17.copyassignable) — *Cpp17CopyAssignable* requirements (in addition to [*Cpp17MoveAssignable*](#:Cpp17MoveAssignable "16.4.4.2 Template argument requirements [utility.arg.requirements]")) [[tab:cpp17.copyassignable]](./tab:cpp17.copyassignable)
|
||
|
||
| [ð](#tab:cpp17.copyassignable-row-1)<br>**Expression** | **Return type** | **Return value** | **Post-condition** |
|
||
| --- | --- | --- | --- |
|
||
| [ð](#tab:cpp17.copyassignable-row-2)<br>t = v | T& | t | t is equivalent to v, the value of v is unchanged |
|
||
|
||
Table [35](#tab:cpp17.destructible) — *Cpp17Destructible* requirements [[tab:cpp17.destructible]](./tab:cpp17.destructible)
|
||
|
||
| [ð](#tab:cpp17.destructible-row-1)<br>**Expression** | **Post-condition** |
|
||
| --- | --- |
|
||
| [ð](#tab:cpp17.destructible-row-2)<br>u.~T() | All resources owned by u are reclaimed, no exception is propagated[.](#tab:cpp17.destructible-row-2-column-2-sentence-1) |
|
||
| [ð](#tab:cpp17.destructible-row-3)<br>[*Note [3](#tab:cpp17.destructible-row-3-column-1-note-3)*:<br>Array types and non-object types are not [*Cpp17Destructible*](#:Cpp17Destructible "16.4.4.2 Template argument requirements [utility.arg.requirements]")[.](#tab:cpp17.destructible-row-3-column-1-sentence-1) â *end note*] | |
|
||
|
||
#### [16.4.4.3](#swappable.requirements) Swappable requirements [[swappable.requirements]](swappable.requirements)
|
||
|
||
[1](#swappable.requirements-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1913)
|
||
|
||
This subclause provides definitions for swappable types and expressions[.](#swappable.requirements-1.sentence-1)
|
||
|
||
In these
|
||
definitions, let t denote an expression of type T, and let u denote an expression of type U[.](#swappable.requirements-1.sentence-2)
|
||
|
||
[2](#swappable.requirements-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1918)
|
||
|
||
An object t is [*swappable with*](#def:swappable_with "16.4.4.3 Swappable requirements [swappable.requirements]") an object u if and only if
|
||
|
||
- [(2.1)](#swappable.requirements-2.1)
|
||
|
||
the expressions swap(t, u) and swap(u, t) are valid when
|
||
evaluated in the context described below, and
|
||
|
||
- [(2.2)](#swappable.requirements-2.2)
|
||
|
||
these expressions have the following effects:
|
||
* [(2.2.1)](#swappable.requirements-2.2.1)
|
||
|
||
the object referred to by t has the value originally held by u and
|
||
|
||
* [(2.2.2)](#swappable.requirements-2.2.2)
|
||
|
||
the object referred to by u has the value originally held by t[.](#swappable.requirements-2.sentence-1)
|
||
|
||
[3](#swappable.requirements-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1931)
|
||
|
||
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](over.match "12.2 Overload resolution [over.match]") on a candidate set that includes:
|
||
|
||
- [(3.1)](#swappable.requirements-3.1)
|
||
|
||
the two swap function templates defined in[<utility>](utility.syn#header:%3cutility%3e "22.2.1 Header <utility> synopsis [utility.syn]") and
|
||
|
||
- [(3.2)](#swappable.requirements-3.2)
|
||
|
||
the lookup set produced by [argument-dependent lookup](basic.lookup.argdep "6.5.4 Argument-dependent name lookup [basic.lookup.argdep]")[.](#swappable.requirements-3.sentence-1)
|
||
|
||
[*Note [1](#swappable.requirements-note-1)*:
|
||
|
||
If T and U are both fundamental types or arrays of
|
||
fundamental types and the declarations from the header [<utility>](utility.syn#header:%3cutility%3e "22.2.1 Header <utility> synopsis [utility.syn]") 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[.](#swappable.requirements-3.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
[*Note [2](#swappable.requirements-note-2)*:
|
||
|
||
It is unspecified whether a library component that has a swappable
|
||
requirement includes the header [<utility>](utility.syn#header:%3cutility%3e "22.2.1 Header <utility> synopsis [utility.syn]") to ensure an appropriate
|
||
evaluation context[.](#swappable.requirements-3.sentence-3)
|
||
|
||
â *end note*]
|
||
|
||
[4](#swappable.requirements-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1954)
|
||
|
||
An rvalue or lvalue t is [*swappable*](#def:swappable "16.4.4.3 Swappable requirements [swappable.requirements]") if and only if t is
|
||
swappable with any rvalue or lvalue, respectively, of type T[.](#swappable.requirements-4.sentence-1)
|
||
|
||
[5](#swappable.requirements-5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1958)
|
||
|
||
A type X meets the *Cpp17Swappable* requirements
|
||
if lvalues of type X are swappable[.](#swappable.requirements-5.sentence-1)
|
||
|
||
[6](#swappable.requirements-6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1962)
|
||
|
||
A type X meeting any of the iterator requirements ([[iterator.requirements]](iterator.requirements "24.3 Iterator requirements"))
|
||
meets the *Cpp17ValueSwappable* requirements if,
|
||
for any dereferenceable objectx of type X,*x is swappable[.](#swappable.requirements-6.sentence-1)
|
||
|
||
[7](#swappable.requirements-7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L1969)
|
||
|
||
[*Example [1](#swappable.requirements-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 <cassert>#include <utility>// Preconditions: std::forward<T>(t) is swappable with std::forward<U>(u).template<class T, class U>void value_swap(T&& t, U&& u) {using std::swap;
|
||
swap(std::forward<T>(t), std::forward<U>(u)); // OK, uses âswappable with'' conditions// for rvalues and lvalues}// Preconditions: T meets the [*Cpp17Swappable*](#:Cpp17Swappable "16.4.4.3 Swappable requirements [swappable.requirements]") requirements.template<class T>void 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](#nullablepointer.requirements) *Cpp17NullablePointer* requirements [[nullablepointer.requirements]](nullablepointer.requirements)
|
||
|
||
[1](#nullablepointer.requirements-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2018)
|
||
|
||
A *Cpp17NullablePointer* type is a pointer-like type that supports null values[.](#nullablepointer.requirements-1.sentence-1)
|
||
|
||
A type P meets the *Cpp17NullablePointer* requirements if
|
||
|
||
- [(1.1)](#nullablepointer.requirements-1.1)
|
||
|
||
P meets the [*Cpp17EqualityComparable*](#:Cpp17EqualityComparable "16.4.4.2 Template argument requirements [utility.arg.requirements]"),[*Cpp17DefaultConstructible*](#:Cpp17DefaultConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]"), [*Cpp17CopyConstructible*](#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]"), *Cpp17CopyAssignable*,[*Cpp17Swappable*](#:Cpp17Swappable "16.4.4.3 Swappable requirements [swappable.requirements]"), and [*Cpp17Destructible*](#:Cpp17Destructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements,
|
||
|
||
- [(1.2)](#nullablepointer.requirements-1.2)
|
||
|
||
the expressions shown in Table [36](#tab:cpp17.nullablepointer "Table 36: Cpp17NullablePointer requirements") are
|
||
valid and have the indicated semantics, and
|
||
|
||
- [(1.3)](#nullablepointer.requirements-1.3)
|
||
|
||
P meets all the other requirements of this subclause[.](#nullablepointer.requirements-1.sentence-2)
|
||
|
||
[2](#nullablepointer.requirements-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2032)
|
||
|
||
A value-initialized object of type P produces the null value of the type[.](#nullablepointer.requirements-2.sentence-1)
|
||
|
||
The null value shall be equivalent only to itself[.](#nullablepointer.requirements-2.sentence-2)
|
||
|
||
A default-initialized object
|
||
of type P may have an indeterminate or erroneous value[.](#nullablepointer.requirements-2.sentence-3)
|
||
|
||
[*Note [1](#nullablepointer.requirements-note-1)*:
|
||
|
||
Operations involving indeterminate values can cause undefined behavior, and
|
||
operations involving erroneous values can cause erroneous behavior ([[basic.indet]](basic.indet "6.8.5 Indeterminate and erroneous values"))[.](#nullablepointer.requirements-2.sentence-4)
|
||
|
||
â *end note*]
|
||
|
||
[3](#nullablepointer.requirements-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2041)
|
||
|
||
An object p of type P can be[contextually converted to bool](conv#def:conversion,contextual_to_bool "7.3 Standard conversions [conv]")[.](#nullablepointer.requirements-3.sentence-1)
|
||
|
||
The effect shall be as if p != nullptr had been evaluated in place of p[.](#nullablepointer.requirements-3.sentence-2)
|
||
|
||
[4](#nullablepointer.requirements-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2047)
|
||
|
||
No operation which is part of the *Cpp17NullablePointer* requirements shall exit
|
||
via an exception[.](#nullablepointer.requirements-4.sentence-1)
|
||
|
||
[5](#nullablepointer.requirements-5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2051)
|
||
|
||
In Table [36](#tab:cpp17.nullablepointer "Table 36: Cpp17NullablePointer requirements"), 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[.](#nullablepointer.requirements-5.sentence-1)
|
||
|
||
Table [36](#tab:cpp17.nullablepointer) — *Cpp17NullablePointer* requirements [[tab:cpp17.nullablepointer]](./tab:cpp17.nullablepointer)
|
||
|
||
| [ð](#tab:cpp17.nullablepointer-row-1)<br>**Expression** | **Return type** | **Operational semantics** |
|
||
| --- | --- | --- |
|
||
| [ð](#tab:cpp17.nullablepointer-row-2)<br>P u(np); | | *Postconditions*: u == nullptr |
|
||
| [ð](#tab:cpp17.nullablepointer-row-3)<br>P u = np; | | |
|
||
| [ð](#tab:cpp17.nullablepointer-row-4)<br>P(np) | | *Postconditions*: P(np) == nullptr |
|
||
| [ð](#tab:cpp17.nullablepointer-row-5)<br>t = np | P& | *Postconditions*: t == nullptr |
|
||
| [ð](#tab:cpp17.nullablepointer-row-6)<br>a != b | decltype(a != b) models [*boolean-testable*](concept.booleantestable#concept:boolean-testable "18.5.2 Boolean testability [concept.booleantestable]") | !(a == b) |
|
||
| [ð](#tab:cpp17.nullablepointer-row-7)<br>a == np | decltype(a == np) and decltype(np == a) each model [*boolean-testable*](concept.booleantestable#concept:boolean-testable "18.5.2 Boolean testability [concept.booleantestable]") | a == P() |
|
||
| [ð](#tab:cpp17.nullablepointer-row-8)<br>np == a | | |
|
||
| [ð](#tab:cpp17.nullablepointer-row-9)<br>a != np | decltype(a != np) and decltype(np != a) each model [*boolean-testable*](concept.booleantestable#concept:boolean-testable "18.5.2 Boolean testability [concept.booleantestable]") | !(a == np) |
|
||
| [ð](#tab:cpp17.nullablepointer-row-10)<br>np != a | | |
|
||
|
||
#### [16.4.4.5](#hash.requirements) *Cpp17Hash* requirements [[hash.requirements]](hash.requirements)
|
||
|
||
[1](#hash.requirements-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2096)
|
||
|
||
A type H meets the *Cpp17Hash* requirements if
|
||
|
||
- [(1.1)](#hash.requirements-1.1)
|
||
|
||
it is a function object type ([[function.objects]](function.objects "22.10 Function objects")),
|
||
|
||
- [(1.2)](#hash.requirements-1.2)
|
||
|
||
it meets the [*Cpp17CopyConstructible*](#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") (Table [32](#tab:cpp17.copyconstructible "Table 32: Cpp17CopyConstructible requirements (in addition to Cpp17MoveConstructible)")) and [*Cpp17Destructible*](#:Cpp17Destructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") (Table [35](#tab:cpp17.destructible "Table 35: Cpp17Destructible requirements")) requirements, and
|
||
|
||
- [(1.3)](#hash.requirements-1.3)
|
||
|
||
the expressions shown in Table [37](#tab:cpp17.hash "Table 37: Cpp17Hash requirements") are valid and have the indicated semantics[.](#hash.requirements-1.sentence-1)
|
||
|
||
[2](#hash.requirements-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2106)
|
||
|
||
Given Key is an argument type for function objects of type H, in
|
||
Table [37](#tab:cpp17.hash "Table 37: Cpp17Hash requirements") 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[.](#hash.requirements-2.sentence-1)
|
||
|
||
Table [37](#tab:cpp17.hash) — *Cpp17Hash* requirements [[tab:cpp17.hash]](./tab:cpp17.hash)
|
||
|
||
| [ð](#tab:cpp17.hash-row-1)<br>**Expression** | **Return type** | **Requirement** |
|
||
| --- | --- | --- |
|
||
| [ð](#tab:cpp17.hash-row-2)<br>h(k) | size_t | The value returned shall depend only on the argument k for the duration of the program[.](#tab:cpp17.hash-row-2-column-3-sentence-1)<br>[*Note [1](#tab:cpp17.hash-row-2-column-3-note-1)*:<br>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[.](#tab:cpp17.hash-row-2-column-3-sentence-2) â *end note*]<br> 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()[.](#tab:cpp17.hash-row-2-column-3-sentence-3) |
|
||
| [ð](#tab:cpp17.hash-row-3)<br>h(u) | size_t | Shall not modify u[.](#tab:cpp17.hash-row-3-column-3-sentence-1) |
|
||
|
||
#### [16.4.4.6](#allocator.requirements) *Cpp17Allocator* requirements [[allocator.requirements]](allocator.requirements)
|
||
|
||
#### [16.4.4.6.1](#allocator.requirements.general) General [[allocator.requirements.general]](allocator.requirements.general)
|
||
|
||
[1](#allocator.requirements.general-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2138)
|
||
|
||
The library describes a standard set of requirements for [*allocators*](#def:allocators),
|
||
which are class-type objects that encapsulate the information about an allocation model[.](#allocator.requirements.general-1.sentence-1)
|
||
|
||
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[.](#allocator.requirements.general-1.sentence-2)
|
||
|
||
All of the
|
||
string types ([[strings]](strings "27 Strings library")),
|
||
containers ([[containers]](containers "23 Containers library")) (except array and inplace_vector),
|
||
string buffers and string streams ([[input.output]](input.output "31 Input/output library")), and[match_results](re "28.6 Regular expressions library [re]") are parameterized in terms of
|
||
allocators[.](#allocator.requirements.general-1.sentence-3)
|
||
|
||
[2](#allocator.requirements.general-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2150)
|
||
|
||
In [[allocator.requirements]](#allocator.requirements "16.4.4.6 Cpp17Allocator requirements"),
|
||
|
||
- [(2.1)](#allocator.requirements.general-2.1)
|
||
|
||
T, U, C denote
|
||
any cv-unqualified object type ([[basic.types.general]](basic.types.general#term.object.type "6.9.1 General")),
|
||
|
||
- [(2.2)](#allocator.requirements.general-2.2)
|
||
|
||
X denotes an allocator class for type T,
|
||
|
||
- [(2.3)](#allocator.requirements.general-2.3)
|
||
|
||
Y denotes the corresponding allocator class for type U,
|
||
|
||
- [(2.4)](#allocator.requirements.general-2.4)
|
||
|
||
XX denotes the type allocator_traits<X>,
|
||
|
||
- [(2.5)](#allocator.requirements.general-2.5)
|
||
|
||
YY denotes the type allocator_traits<Y>,
|
||
|
||
- [(2.6)](#allocator.requirements.general-2.6)
|
||
|
||
a, a1, a2 denote lvalues of type X,
|
||
|
||
- [(2.7)](#allocator.requirements.general-2.7)
|
||
|
||
u denotes the name of a variable being declared,
|
||
|
||
- [(2.8)](#allocator.requirements.general-2.8)
|
||
|
||
b denotes a value of type Y,
|
||
|
||
- [(2.9)](#allocator.requirements.general-2.9)
|
||
|
||
c denotes a pointer of type C* through which indirection is valid,
|
||
|
||
- [(2.10)](#allocator.requirements.general-2.10)
|
||
|
||
p denotes a value of type XX::pointer obtained by calling a1.allocate, where a1 == a,
|
||
|
||
- [(2.11)](#allocator.requirements.general-2.11)
|
||
|
||
q denotes a value of type XX::const_pointer obtained by conversion from a value p,
|
||
|
||
- [(2.12)](#allocator.requirements.general-2.12)
|
||
|
||
r denotes a value of type T& obtained by the expression *p,
|
||
|
||
- [(2.13)](#allocator.requirements.general-2.13)
|
||
|
||
w denotes a value of type XX::void_pointer obtained by conversion from a value p,
|
||
|
||
- [(2.14)](#allocator.requirements.general-2.14)
|
||
|
||
x denotes a value of type XX::const_void_pointer obtained by conversion from a value q or a value w,
|
||
|
||
- [(2.15)](#allocator.requirements.general-2.15)
|
||
|
||
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,
|
||
|
||
- [(2.16)](#allocator.requirements.general-2.16)
|
||
|
||
n denotes a value of type XX::size_type,
|
||
|
||
- [(2.17)](#allocator.requirements.general-2.17)
|
||
|
||
Args denotes a template parameter pack, and
|
||
|
||
- [(2.18)](#allocator.requirements.general-2.18)
|
||
|
||
args denotes
|
||
a function parameter pack with the pattern Args&&[.](#allocator.requirements.general-2.sentence-1)
|
||
|
||
[3](#allocator.requirements.general-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2201)
|
||
|
||
The class template allocator_traits ([[allocator.traits]](allocator.traits "20.2.9 Allocator traits")) supplies
|
||
a uniform interface to all allocator types[.](#allocator.requirements.general-3.sentence-1)
|
||
|
||
This subclause
|
||
describes the requirements on allocator types
|
||
and thus on types used to instantiate allocator_traits[.](#allocator.requirements.general-3.sentence-2)
|
||
|
||
A requirement is optional if a default for a
|
||
given type or expression is specified[.](#allocator.requirements.general-3.sentence-3)
|
||
|
||
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[.](#allocator.requirements.general-3.sentence-4)
|
||
|
||
[*Note [1](#allocator.requirements.general-note-1)*:
|
||
|
||
There are no program-defined specializations of allocator_traits[.](#allocator.requirements.general-3.sentence-5)
|
||
|
||
â *end note*]
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:1)
|
||
|
||
`typename X::pointer
|
||
`
|
||
|
||
[4](#allocator.requirements.general-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2221)
|
||
|
||
*Remarks*: Default: T*
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:2)
|
||
|
||
`typename X::const_pointer
|
||
`
|
||
|
||
[5](#allocator.requirements.general-5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2231)
|
||
|
||
*Mandates*: XX::pointer is convertible to XX::const_pointer[.](#allocator.requirements.general-5.sentence-1)
|
||
|
||
[6](#allocator.requirements.general-6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2235)
|
||
|
||
*Remarks*: Default: pointer_traits<XX::pointer>::rebind<const T>
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:3)
|
||
|
||
`typename X::void_pointer
|
||
typename Y::void_pointer
|
||
`
|
||
|
||
[7](#allocator.requirements.general-7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2246)
|
||
|
||
*Mandates*: XX::pointer is convertible to XX::void_pointer[.](#allocator.requirements.general-7.sentence-1)
|
||
|
||
XX::void_pointer and YY::void_pointer are the same type[.](#allocator.requirements.general-7.sentence-2)
|
||
|
||
[8](#allocator.requirements.general-8)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2251)
|
||
|
||
*Remarks*: Default:pointer_traits<XX::pointer>::rebind<void>
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:4)
|
||
|
||
`typename X::const_void_pointer
|
||
typename Y::const_void_pointer
|
||
`
|
||
|
||
[9](#allocator.requirements.general-9)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2263)
|
||
|
||
*Mandates*: XX::pointer, XX::const_pointer, and XX::void_pointer are convertible to XX::const_void_pointer[.](#allocator.requirements.general-9.sentence-1)
|
||
|
||
XX::const_void_pointer and YY::const_void_pointer are the same type[.](#allocator.requirements.general-9.sentence-2)
|
||
|
||
[10](#allocator.requirements.general-10)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2270)
|
||
|
||
*Remarks*: Default:pointer_traits<XX::pointer>::rebind<const void>
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:5)
|
||
|
||
`typename X::value_type
|
||
`
|
||
|
||
[11](#allocator.requirements.general-11)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2281)
|
||
|
||
*Result*: Identical to T[.](#allocator.requirements.general-11.sentence-1)
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:6)
|
||
|
||
`typename X::size_type
|
||
`
|
||
|
||
[12](#allocator.requirements.general-12)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2291)
|
||
|
||
*Result*: An unsigned integer type
|
||
that can represent the size of the largest object in the allocation model[.](#allocator.requirements.general-12.sentence-1)
|
||
|
||
[13](#allocator.requirements.general-13)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2296)
|
||
|
||
*Remarks*: Default:make_unsigned_t<XX::difference_type>
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:7)
|
||
|
||
`typename X::difference_type
|
||
`
|
||
|
||
[14](#allocator.requirements.general-14)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2307)
|
||
|
||
*Result*: A signed integer type that can represent
|
||
the difference between any two pointers in the allocation model[.](#allocator.requirements.general-14.sentence-1)
|
||
|
||
[15](#allocator.requirements.general-15)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2312)
|
||
|
||
*Remarks*: Default:pointer_traits<XX::pointer>::difference_type
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:8)
|
||
|
||
`typename X::rebind<U>::other
|
||
`
|
||
|
||
[16](#allocator.requirements.general-16)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2323)
|
||
|
||
*Result*: Y
|
||
|
||
[17](#allocator.requirements.general-17)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2327)
|
||
|
||
*Postconditions*: For all U (including T),YY::rebind_alloc<T> is X[.](#allocator.requirements.general-17.sentence-1)
|
||
|
||
[18](#allocator.requirements.general-18)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2332)
|
||
|
||
*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<U>::other by default[.](#allocator.requirements.general-18.sentence-1)
|
||
|
||
For allocator types that are not template instantiations of the
|
||
above form, no default is provided[.](#allocator.requirements.general-18.sentence-2)
|
||
|
||
[19](#allocator.requirements.general-19)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2342)
|
||
|
||
[*Note [2](#allocator.requirements.general-note-2)*:
|
||
|
||
The member class template rebind of X is
|
||
effectively a typedef template[.](#allocator.requirements.general-19.sentence-1)
|
||
|
||
In general, if
|
||
the name Allocator is bound to SomeAllocator<T>, thenAllocator::rebind<U>::other is the same type asSomeAllocator<U>, whereSomeAllocator<T>::value_type is T andSomeAllocator<U>::value_type is U[.](#allocator.requirements.general-19.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:9)
|
||
|
||
`*p
|
||
`
|
||
|
||
[20](#allocator.requirements.general-20)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2360)
|
||
|
||
*Result*: T&
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:10)
|
||
|
||
`*q
|
||
`
|
||
|
||
[21](#allocator.requirements.general-21)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2370)
|
||
|
||
*Result*: const T&
|
||
|
||
[22](#allocator.requirements.general-22)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2374)
|
||
|
||
*Postconditions*: *q refers to the same object as *p[.](#allocator.requirements.general-22.sentence-1)
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:11)
|
||
|
||
`p->m
|
||
`
|
||
|
||
[23](#allocator.requirements.general-23)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2384)
|
||
|
||
*Result*: Type of T::m[.](#allocator.requirements.general-23.sentence-1)
|
||
|
||
[24](#allocator.requirements.general-24)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2388)
|
||
|
||
*Preconditions*: (*p).m is well-defined[.](#allocator.requirements.general-24.sentence-1)
|
||
|
||
[25](#allocator.requirements.general-25)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2392)
|
||
|
||
*Effects*: Equivalent to (*p).m[.](#allocator.requirements.general-25.sentence-1)
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:12)
|
||
|
||
`q->m
|
||
`
|
||
|
||
[26](#allocator.requirements.general-26)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2402)
|
||
|
||
*Result*: Type of T::m[.](#allocator.requirements.general-26.sentence-1)
|
||
|
||
[27](#allocator.requirements.general-27)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2406)
|
||
|
||
*Preconditions*: (*q).m is well-defined[.](#allocator.requirements.general-27.sentence-1)
|
||
|
||
[28](#allocator.requirements.general-28)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2410)
|
||
|
||
*Effects*: Equivalent to (*q).m[.](#allocator.requirements.general-28.sentence-1)
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:13)
|
||
|
||
`static_cast<XX::pointer>(w)
|
||
`
|
||
|
||
[29](#allocator.requirements.general-29)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2420)
|
||
|
||
*Result*: XX::pointer
|
||
|
||
[30](#allocator.requirements.general-30)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2424)
|
||
|
||
*Postconditions*: static_cast<XX::pointer>(w) == p[.](#allocator.requirements.general-30.sentence-1)
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:14)
|
||
|
||
`static_cast<XX::const_pointer>(x)
|
||
`
|
||
|
||
[31](#allocator.requirements.general-31)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2434)
|
||
|
||
*Result*: XX::const_pointer
|
||
|
||
[32](#allocator.requirements.general-32)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2438)
|
||
|
||
*Postconditions*: static_cast<XX::const_pointer>(x) == q[.](#allocator.requirements.general-32.sentence-1)
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:15)
|
||
|
||
`pointer_traits<XX::pointer>::pointer_to(r)
|
||
`
|
||
|
||
[33](#allocator.requirements.general-33)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2448)
|
||
|
||
*Result*: XX::pointer
|
||
|
||
[34](#allocator.requirements.general-34)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2452)
|
||
|
||
*Postconditions*: Same as p[.](#allocator.requirements.general-34.sentence-1)
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:16)
|
||
|
||
`a.allocate(n)
|
||
`
|
||
|
||
[35](#allocator.requirements.general-35)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2462)
|
||
|
||
*Result*: XX::pointer
|
||
|
||
[36](#allocator.requirements.general-36)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2466)
|
||
|
||
*Effects*: Memory is allocated for an array of n T and such an object is created
|
||
but array elements are not constructed[.](#allocator.requirements.general-36.sentence-1)
|
||
|
||
[*Example [1](#allocator.requirements.general-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[.](#allocator.requirements.general-36.sentence-2)
|
||
|
||
â *end example*]
|
||
|
||
[37](#allocator.requirements.general-37)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2478)
|
||
|
||
*Throws*: allocate may throw an appropriate exception[.](#allocator.requirements.general-37.sentence-1)
|
||
|
||
[38](#allocator.requirements.general-38)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2482)
|
||
|
||
[*Note [3](#allocator.requirements.general-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[.](#allocator.requirements.general-38.sentence-1)
|
||
|
||
That is, there is no need for a container to maintain its own
|
||
free list[.](#allocator.requirements.general-38.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
[39](#allocator.requirements.general-39)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2490)
|
||
|
||
*Remarks*: If n == 0, the return value is unspecified[.](#allocator.requirements.general-39.sentence-1)
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:17)
|
||
|
||
`a.allocate(n, y)
|
||
`
|
||
|
||
[40](#allocator.requirements.general-40)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2500)
|
||
|
||
*Result*: XX::pointer
|
||
|
||
[41](#allocator.requirements.general-41)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2504)
|
||
|
||
*Effects*: Same as a.allocate(n)[.](#allocator.requirements.general-41.sentence-1)
|
||
|
||
The use of y is unspecified, but it is intended as an aid to locality[.](#allocator.requirements.general-41.sentence-2)
|
||
|
||
[42](#allocator.requirements.general-42)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2509)
|
||
|
||
*Remarks*: Default: a.allocate(n)
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:18)
|
||
|
||
`a.allocate_at_least(n)
|
||
`
|
||
|
||
[43](#allocator.requirements.general-43)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2519)
|
||
|
||
*Result*: allocation_result<XX::pointer, XX::size_type>
|
||
|
||
[44](#allocator.requirements.general-44)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2523)
|
||
|
||
*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[.](#allocator.requirements.general-44.sentence-1)
|
||
|
||
If n == 0, the return value is unspecified[.](#allocator.requirements.general-44.sentence-2)
|
||
|
||
[45](#allocator.requirements.general-45)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2531)
|
||
|
||
*Throws*: allocate_at_least may throw an appropriate exception[.](#allocator.requirements.general-45.sentence-1)
|
||
|
||
[46](#allocator.requirements.general-46)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2535)
|
||
|
||
*Remarks*: Default: {a.allocate(n), n}[.](#allocator.requirements.general-46.sentence-1)
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:19)
|
||
|
||
`a.deallocate(p, n)
|
||
`
|
||
|
||
[47](#allocator.requirements.general-47)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2545)
|
||
|
||
*Result*: (not used)
|
||
|
||
[48](#allocator.requirements.general-48)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2549)
|
||
|
||
*Preconditions*:
|
||
|
||
- [(48.1)](#allocator.requirements.general-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[.](#allocator.requirements.general-48.1.sentence-1)
|
||
p is equal to ret.ptr andn is a value such thatreq ⤠n ⤠ret.count[.](#allocator.requirements.general-48.1.sentence-2)
|
||
|
||
- [(48.2)](#allocator.requirements.general-48.2)
|
||
|
||
Otherwise, p is a pointer value obtained from allocate[.](#allocator.requirements.general-48.2.sentence-1)
|
||
n equals the value passed as the first argument
|
||
to the invocation of allocate which returned p[.](#allocator.requirements.general-48.2.sentence-2)
|
||
|
||
p has not been invalidated by
|
||
an intervening call to deallocate[.](#allocator.requirements.general-48.sentence-2)
|
||
|
||
[49](#allocator.requirements.general-49)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2568)
|
||
|
||
*Throws*: Nothing[.](#allocator.requirements.general-49.sentence-1)
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:20)
|
||
|
||
`a.max_size()
|
||
`
|
||
|
||
[50](#allocator.requirements.general-50)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2578)
|
||
|
||
*Result*: XX::size_type
|
||
|
||
[51](#allocator.requirements.general-51)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2582)
|
||
|
||
*Returns*: The largest value n that can meaningfully be passed to a.allocate(n)[.](#allocator.requirements.general-51.sentence-1)
|
||
|
||
[52](#allocator.requirements.general-52)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2586)
|
||
|
||
*Remarks*: Default:numeric_limits<size_type>::max() / sizeof(value_type)
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:21)
|
||
|
||
`a1 == a2
|
||
`
|
||
|
||
[53](#allocator.requirements.general-53)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2597)
|
||
|
||
*Result*: bool
|
||
|
||
[54](#allocator.requirements.general-54)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2601)
|
||
|
||
*Returns*: true only if storage allocated from each can
|
||
be deallocated via the other[.](#allocator.requirements.general-54.sentence-1)
|
||
|
||
[55](#allocator.requirements.general-55)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2606)
|
||
|
||
*Throws*: Nothing[.](#allocator.requirements.general-55.sentence-1)
|
||
|
||
[56](#allocator.requirements.general-56)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2610)
|
||
|
||
*Remarks*: operator== shall be reflexive, symmetric,
|
||
and transitive[.](#allocator.requirements.general-56.sentence-1)
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:22)
|
||
|
||
`a1 != a2
|
||
`
|
||
|
||
[57](#allocator.requirements.general-57)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2621)
|
||
|
||
*Result*: bool
|
||
|
||
[58](#allocator.requirements.general-58)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2625)
|
||
|
||
*Returns*: !(a1 == a2)[.](#allocator.requirements.general-58.sentence-1)
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:23)
|
||
|
||
`a == b
|
||
`
|
||
|
||
[59](#allocator.requirements.general-59)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2635)
|
||
|
||
*Result*: bool
|
||
|
||
[60](#allocator.requirements.general-60)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2639)
|
||
|
||
*Returns*: a == YY::rebind_alloc<T>(b)[.](#allocator.requirements.general-60.sentence-1)
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:24)
|
||
|
||
`a != b
|
||
`
|
||
|
||
[61](#allocator.requirements.general-61)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2649)
|
||
|
||
*Result*: bool
|
||
|
||
[62](#allocator.requirements.general-62)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2653)
|
||
|
||
*Returns*: !(a == b)[.](#allocator.requirements.general-62.sentence-1)
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:25)
|
||
|
||
`X u(a);
|
||
X u = a;
|
||
`
|
||
|
||
[63](#allocator.requirements.general-63)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2664)
|
||
|
||
*Postconditions*: u == a
|
||
|
||
[64](#allocator.requirements.general-64)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2668)
|
||
|
||
*Throws*: Nothing[.](#allocator.requirements.general-64.sentence-1)
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:26)
|
||
|
||
`X u(b);
|
||
`
|
||
|
||
[65](#allocator.requirements.general-65)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2678)
|
||
|
||
*Postconditions*: Y(u) == b and u == X(b)[.](#allocator.requirements.general-65.sentence-1)
|
||
|
||
[66](#allocator.requirements.general-66)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2682)
|
||
|
||
*Throws*: Nothing[.](#allocator.requirements.general-66.sentence-1)
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:27)
|
||
|
||
`X u(std::move(a));
|
||
X u = std::move(a);
|
||
`
|
||
|
||
[67](#allocator.requirements.general-67)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2693)
|
||
|
||
*Postconditions*: The value of a is unchanged and is equal to u[.](#allocator.requirements.general-67.sentence-1)
|
||
|
||
[68](#allocator.requirements.general-68)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2697)
|
||
|
||
*Throws*: Nothing[.](#allocator.requirements.general-68.sentence-1)
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:28)
|
||
|
||
`X u(std::move(b));
|
||
`
|
||
|
||
[69](#allocator.requirements.general-69)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2707)
|
||
|
||
*Postconditions*: u is equal to the prior value of X(b)[.](#allocator.requirements.general-69.sentence-1)
|
||
|
||
[70](#allocator.requirements.general-70)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2711)
|
||
|
||
*Throws*: Nothing[.](#allocator.requirements.general-70.sentence-1)
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:29)
|
||
|
||
`a.construct(c, args...)
|
||
`
|
||
|
||
[71](#allocator.requirements.general-71)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2721)
|
||
|
||
*Result*: (not used)
|
||
|
||
[72](#allocator.requirements.general-72)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2725)
|
||
|
||
*Effects*: Constructs an object of type C at c[.](#allocator.requirements.general-72.sentence-1)
|
||
|
||
[73](#allocator.requirements.general-73)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2729)
|
||
|
||
*Remarks*: Default:construct_at(c, std::forward<Args>(args)...)
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:30)
|
||
|
||
`a.destroy(c)
|
||
`
|
||
|
||
[74](#allocator.requirements.general-74)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2740)
|
||
|
||
*Result*: (not used)
|
||
|
||
[75](#allocator.requirements.general-75)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2744)
|
||
|
||
*Effects*: Destroys the object at c[.](#allocator.requirements.general-75.sentence-1)
|
||
|
||
[76](#allocator.requirements.general-76)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2748)
|
||
|
||
*Remarks*: Default: destroy_at(c)
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:31)
|
||
|
||
`a.select_on_container_copy_construction()
|
||
`
|
||
|
||
[77](#allocator.requirements.general-77)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2758)
|
||
|
||
*Result*: X
|
||
|
||
[78](#allocator.requirements.general-78)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2762)
|
||
|
||
*Returns*: Typically returns either a or X()[.](#allocator.requirements.general-78.sentence-1)
|
||
|
||
[79](#allocator.requirements.general-79)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2766)
|
||
|
||
*Remarks*: Default: return a;
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:32)
|
||
|
||
`typename X::propagate_on_container_copy_assignment
|
||
`
|
||
|
||
[80](#allocator.requirements.general-80)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2776)
|
||
|
||
*Result*: Identical to or derived from true_type or false_type[.](#allocator.requirements.general-80.sentence-1)
|
||
|
||
[81](#allocator.requirements.general-81)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2780)
|
||
|
||
*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*](#:Cpp17CopyAssignable "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements (Table [34](#tab:cpp17.copyassignable "Table 34: Cpp17CopyAssignable requirements (in addition to Cpp17MoveAssignable)")) and
|
||
the copy operation shall not throw exceptions[.](#allocator.requirements.general-81.sentence-1)
|
||
|
||
[82](#allocator.requirements.general-82)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2788)
|
||
|
||
*Remarks*: Default: false_type
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:33)
|
||
|
||
`typename X::propagate_on_container_move_assignment
|
||
`
|
||
|
||
[83](#allocator.requirements.general-83)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2798)
|
||
|
||
*Result*: Identical to or derived from true_type or false_type[.](#allocator.requirements.general-83.sentence-1)
|
||
|
||
[84](#allocator.requirements.general-84)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2802)
|
||
|
||
*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*](#:Cpp17MoveAssignable "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements (Table [33](#tab:cpp17.moveassignable "Table 33: Cpp17MoveAssignable requirements")) and
|
||
the move operation shall not throw exceptions[.](#allocator.requirements.general-84.sentence-1)
|
||
|
||
[85](#allocator.requirements.general-85)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2810)
|
||
|
||
*Remarks*: Default: false_type
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:34)
|
||
|
||
`typename X::propagate_on_container_swap
|
||
`
|
||
|
||
[86](#allocator.requirements.general-86)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2820)
|
||
|
||
*Result*: Identical to or derived from true_type or false_type[.](#allocator.requirements.general-86.sentence-1)
|
||
|
||
[87](#allocator.requirements.general-87)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2824)
|
||
|
||
*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*](#:Cpp17Swappable "16.4.4.3 Swappable requirements [swappable.requirements]") requirements ([[swappable.requirements]](#swappable.requirements "16.4.4.3 Swappable requirements")) and
|
||
the swap operation shall not throw exceptions[.](#allocator.requirements.general-87.sentence-1)
|
||
|
||
[88](#allocator.requirements.general-88)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2832)
|
||
|
||
*Remarks*: Default: false_type
|
||
|
||
[ð](#allocator.requirements.general-itemdecl:35)
|
||
|
||
`typename X::is_always_equal
|
||
`
|
||
|
||
[89](#allocator.requirements.general-89)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2842)
|
||
|
||
*Result*: Identical to or derived from true_type or false_type[.](#allocator.requirements.general-89.sentence-1)
|
||
|
||
[90](#allocator.requirements.general-90)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2846)
|
||
|
||
*Returns*: true_type only if the expression a1 == a2 is guaranteed
|
||
to be true for any two (possibly const) valuesa1, a2 of type X[.](#allocator.requirements.general-90.sentence-1)
|
||
|
||
[91](#allocator.requirements.general-91)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2852)
|
||
|
||
*Remarks*: Default: is_empty<X>::type
|
||
|
||
[92](#allocator.requirements.general-92)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2857)
|
||
|
||
An allocator type X shall meet the[*Cpp17CopyConstructible*](#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements (Table [32](#tab:cpp17.copyconstructible "Table 32: Cpp17CopyConstructible requirements (in addition to Cpp17MoveConstructible)"))[.](#allocator.requirements.general-92.sentence-1)
|
||
|
||
The XX::pointer, XX::const_pointer, XX::void_pointer, andXX::const_void_pointer types shall meet the*Cpp17NullablePointer* requirements (Table [36](#tab:cpp17.nullablepointer "Table 36: Cpp17NullablePointer requirements"))[.](#allocator.requirements.general-92.sentence-2)
|
||
|
||
No constructor,
|
||
comparison operator function, copy operation, move operation, or swap operation on
|
||
these pointer types shall exit via an exception[.](#allocator.requirements.general-92.sentence-3)
|
||
|
||
XX::pointer and XX::const_pointer shall also
|
||
meet the requirements for
|
||
a [*Cpp17RandomAccessIterator*](random.access.iterators#:Cpp17RandomAccessIterator "24.3.5.7 Random access iterators [random.access.iterators]") ([[random.access.iterators]](random.access.iterators "24.3.5.7 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[.](#allocator.requirements.general-92.sentence-4)
|
||
|
||
[93](#allocator.requirements.general-93)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2875)
|
||
|
||
Let x1 and x2 denote objects of (possibly different) typesXX::void_pointer, XX::const_void_pointer, XX::pointer,
|
||
or XX::const_pointer[.](#allocator.requirements.general-93.sentence-1)
|
||
|
||
Then, x1 and x2 are[*equivalently-valued*](#def:equivalently-valued "16.4.4.6.1 General [allocator.requirements.general]") 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[.](#allocator.requirements.general-93.sentence-2)
|
||
|
||
[94](#allocator.requirements.general-94)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2885)
|
||
|
||
Let w1 and w2 denote objects of type XX::void_pointer[.](#allocator.requirements.general-94.sentence-1)
|
||
|
||
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[.](#allocator.requirements.general-94.sentence-2)
|
||
|
||
[95](#allocator.requirements.general-95)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2895)
|
||
|
||
Let p1 and p2 denote objects of type XX::pointer[.](#allocator.requirements.general-95.sentence-1)
|
||
|
||
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[.](#allocator.requirements.general-95.sentence-2)
|
||
|
||
[96](#allocator.requirements.general-96)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2910)
|
||
|
||
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[.](#allocator.requirements.general-96.sentence-1)
|
||
|
||
If a type cannot be used with a particular allocator, the allocator
|
||
class or the call to construct or destroy may fail to instantiate[.](#allocator.requirements.general-96.sentence-2)
|
||
|
||
[97](#allocator.requirements.general-97)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2916)
|
||
|
||
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[.](#allocator.requirements.general-97.sentence-1)
|
||
|
||
The allocator also may silently ignore the requested alignment[.](#allocator.requirements.general-97.sentence-2)
|
||
|
||
[*Note [4](#allocator.requirements.general-note-4)*:
|
||
|
||
Additionally, the member function allocate for that type can fail by throwing an object of typebad_alloc[.](#allocator.requirements.general-97.sentence-3)
|
||
|
||
â *end note*]
|
||
|
||
[98](#allocator.requirements.general-98)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2926)
|
||
|
||
[*Example [2](#allocator.requirements.general-example-2)*:
|
||
|
||
The following is an allocator class template supporting the minimal
|
||
interface that meets the requirements of [[allocator.requirements.general]](#allocator.requirements.general "16.4.4.6.1 General"):template<class T>struct SimpleAllocator {using value_type = T;
|
||
SimpleAllocator(*ctor args*); template<class U> SimpleAllocator(const SimpleAllocator<U>& other);
|
||
|
||
T* allocate(std::size_t n); void deallocate(T* p, std::size_t n); template<class U> bool operator==(const SimpleAllocator<U>& rhs) const;};
|
||
|
||
â *end example*]
|
||
|
||
[99](#allocator.requirements.general-99)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2946)
|
||
|
||
The following exposition-only concept defines
|
||
the minimal requirements on an Allocator type[.](#allocator.requirements.general-99.sentence-1)
|
||
|
||
template<class Alloc>concept [*simple-allocator*](#concept:simple-allocator "16.4.4.6.1 General [allocator.requirements.general]") =requires(Alloc alloc, size_t n) {{ *alloc.allocate(n) } -> [same_as](concept.same#concept:same_as "18.4.2 Concept same_as [concept.same]")<typename Alloc::value_type&>; { alloc.deallocate(alloc.allocate(n), n) }; } &&[copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14 Concept copy_constructible [concept.copyconstructible]")<Alloc> &&[equality_comparable](concept.equalitycomparable#concept:equality_comparable "18.5.4 Concept equality_comparable [concept.equalitycomparable]")<Alloc>;
|
||
|
||
A type Alloc models [*simple-allocator*](#concept:simple-allocator "16.4.4.6.1 General [allocator.requirements.general]") if it meets the requirements of [[allocator.requirements.general]](#allocator.requirements.general "16.4.4.6.1 General")[.](#allocator.requirements.general-99.sentence-2)
|
||
|
||
#### [16.4.4.6.2](#allocator.requirements.completeness) Allocator completeness requirements [[allocator.requirements.completeness]](allocator.requirements.completeness)
|
||
|
||
[1](#allocator.requirements.completeness-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2964)
|
||
|
||
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:
|
||
|
||
- [(1.1)](#allocator.requirements.completeness-1.1)
|
||
|
||
X is a complete type, and
|
||
|
||
- [(1.2)](#allocator.requirements.completeness-1.2)
|
||
|
||
all the member types of [allocator_traits<X>](allocator.traits "20.2.9 Allocator traits [allocator.traits]") other than value_type are complete types[.](#allocator.requirements.completeness-1.sentence-1)
|
||
|
||
### [16.4.5](#constraints) Constraints on programs [[constraints]](constraints)
|
||
|
||
#### [16.4.5.1](#constraints.overview) Overview [[constraints.overview]](constraints.overview)
|
||
|
||
[1](#constraints.overview-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2978)
|
||
|
||
Subclause [[constraints]](#constraints "16.4.5 Constraints on programs") describes restrictions on C++ programs that use the facilities of
|
||
the C++ standard library[.](#constraints.overview-1.sentence-1)
|
||
|
||
The following subclauses specify constraints on the
|
||
program's use of [namespaces](#namespace.std "16.4.5.2.1 Namespace std [namespace.std]"), its use of various [reserved
|
||
names](#reserved.names "16.4.5.3 Reserved names [reserved.names]"), its use of [headers](#alt.headers "16.4.5.4 Headers [alt.headers]"), its use of
|
||
standard library classes as base classes ([[derived.classes]](#derived.classes "16.4.5.5 Derived classes")), its
|
||
definitions of [replacement functions](#replacement.functions "16.4.5.6 Replacement functions [replacement.functions]"), and its
|
||
installation of [handler functions](#handler.functions "16.4.5.7 Handler functions [handler.functions]") during execution[.](#constraints.overview-1.sentence-2)
|
||
|
||
#### [16.4.5.2](#namespace.constraints) Namespace use [[namespace.constraints]](namespace.constraints)
|
||
|
||
#### [16.4.5.2.1](#namespace.std) Namespace std [[namespace.std]](namespace.std)
|
||
|
||
[1](#namespace.std-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2991)
|
||
|
||
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[.](#namespace.std-1.sentence-1)
|
||
|
||
[2](#namespace.std-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L2998)
|
||
|
||
Unless explicitly prohibited,
|
||
a program may add a template specialization for
|
||
any standard library class template
|
||
to namespacestd provided that
|
||
|
||
- [(2.1)](#namespace.std-2.1)
|
||
|
||
the added declaration
|
||
depends on at least one program-defined type, and
|
||
|
||
- [(2.2)](#namespace.std-2.2)
|
||
|
||
the specialization meets the standard library requirements
|
||
for the original template[.](#namespace.std-2.sentence-1)[151](#footnote-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.")
|
||
|
||
[3](#namespace.std-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3018)
|
||
|
||
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[.](#namespace.std-3.sentence-1)
|
||
|
||
[*Note [1](#namespace.std-note-1)*:
|
||
|
||
The requirements on an explicit or partial specialization
|
||
are stated by each variable template that grants such permission[.](#namespace.std-3.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
[4](#namespace.std-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3028)
|
||
|
||
The behavior of a C++ program is undefined if it declares
|
||
|
||
- [(4.1)](#namespace.std-4.1)
|
||
|
||
an explicit specialization of any member function of a standard
|
||
library class template, or
|
||
|
||
- [(4.2)](#namespace.std-4.2)
|
||
|
||
an explicit specialization of any member function template of a
|
||
standard library class or class template, or
|
||
|
||
- [(4.3)](#namespace.std-4.3)
|
||
|
||
an explicit or partial specialization of any member class template
|
||
of a standard library class or class template, or
|
||
|
||
- [(4.4)](#namespace.std-4.4)
|
||
|
||
a deduction guide for any standard library class template[.](#namespace.std-4.sentence-1)
|
||
|
||
[5](#namespace.std-5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3043)
|
||
|
||
A program may explicitly instantiate
|
||
a class template defined in the standard library
|
||
only if the declaration
|
||
|
||
- [(5.1)](#namespace.std-5.1)
|
||
|
||
depends on the name of at least one program-defined type, and
|
||
|
||
- [(5.2)](#namespace.std-5.2)
|
||
|
||
the instantiation meets the standard library requirements for the
|
||
original template[.](#namespace.std-5.sentence-1)
|
||
|
||
[6](#namespace.std-6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3054)
|
||
|
||
Let *F* denote
|
||
a standard library function ([[global.functions]](#global.functions "16.4.6.4 Non-member functions")),
|
||
a standard library static member function,
|
||
or an instantiation
|
||
of a standard library function template[.](#namespace.std-6.sentence-1)
|
||
|
||
Unless *F* is designated
|
||
an [*addressable function*](#def:function,addressable "16.4.5.2.1 Namespace std [namespace.std]"),
|
||
the behavior of a C++ program is unspecified (possibly ill-formed)
|
||
if it explicitly or implicitly attempts
|
||
to form a pointer
|
||
to *F*[.](#namespace.std-6.sentence-2)
|
||
|
||
[*Note [2](#namespace.std-note-2)*:
|
||
|
||
Possible means of forming such pointers include
|
||
application of the unary & operator ([[expr.unary.op]](expr.unary.op "7.6.2.2 Unary operators")),addressof ([[specialized.addressof]](specialized.addressof "20.2.11 addressof")),
|
||
or
|
||
a function-to-pointer standard conversion ([[conv.func]](conv.func "7.3.4 Function-to-pointer conversion"))[.](#namespace.std-6.sentence-3)
|
||
|
||
â *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]](#member.functions "16.4.6.5 Member functions"))
|
||
or an instantiation of a standard library member function template[.](#namespace.std-6.sentence-4)
|
||
|
||
[7](#namespace.std-7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3082)
|
||
|
||
Let *F* denote
|
||
a standard library function or function template[.](#namespace.std-7.sentence-1)
|
||
|
||
Unless *F* is designated an addressable function,
|
||
it is unspecified if or how
|
||
a reflection value designating the associated entity can be formed[.](#namespace.std-7.sentence-2)
|
||
|
||
[*Note [3](#namespace.std-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[.](#namespace.std-7.sentence-3)
|
||
|
||
â *end note*]
|
||
|
||
[8](#namespace.std-8)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3095)
|
||
|
||
Let *C* denote
|
||
a standard library class or class template specialization[.](#namespace.std-8.sentence-1)
|
||
|
||
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[.](#namespace.std-8.sentence-2)
|
||
|
||
[9](#namespace.std-9)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3102)
|
||
|
||
A translation unit shall not declare namespace std to be an inline namespace ([[namespace.def]](namespace.def "9.9.2 Namespace definition"))[.](#namespace.std-9.sentence-1)
|
||
|
||
[151)](#footnote-151)[151)](#footnoteref-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[.](#footnote-151.sentence-1)
|
||
|
||
#### [16.4.5.2.2](#namespace.posix) Namespace posix [[namespace.posix]](namespace.posix)
|
||
|
||
[1](#namespace.posix-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3107)
|
||
|
||
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[.](#namespace.posix-1.sentence-1)
|
||
|
||
The namespace posix is reserved for use by
|
||
ISO/IEC/IEEE 9945 and other POSIX standards[.](#namespace.posix-1.sentence-2)
|
||
|
||
#### [16.4.5.2.3](#namespace.future) Namespaces for future standardization [[namespace.future]](namespace.future)
|
||
|
||
[1](#namespace.future-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3117)
|
||
|
||
Top-level namespaces whose [*namespace-name*](namespace.def.general#nt:namespace-name "9.9.2.1 General [namespace.def.general]") consists of std followed by one or more [*digit*](lex.name#nt:digit "5.11 Identifiers [lex.name]")*s* ([[lex.name]](lex.name "5.11 Identifiers"))
|
||
are reserved for future standardization[.](#namespace.future-1.sentence-1)
|
||
|
||
The behavior of a C++ program is undefined if
|
||
it adds declarations or definitions to such a namespace[.](#namespace.future-1.sentence-2)
|
||
|
||
[*Example [1](#namespace.future-example-1)*:
|
||
|
||
The top-level namespace std2 is reserved
|
||
for use by future revisions of this International Standard[.](#namespace.future-1.sentence-3)
|
||
|
||
â *end example*]
|
||
|
||
#### [16.4.5.3](#reserved.names) Reserved names [[reserved.names]](reserved.names)
|
||
|
||
#### [16.4.5.3.1](#reserved.names.general) General [[reserved.names.general]](reserved.names.general)
|
||
|
||
[1](#reserved.names.general-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3133)
|
||
|
||
The C++ standard library reserves the following kinds of names:
|
||
|
||
- [(1.1)](#reserved.names.general-1.1)
|
||
|
||
macros
|
||
|
||
- [(1.2)](#reserved.names.general-1.2)
|
||
|
||
global names
|
||
|
||
- [(1.3)](#reserved.names.general-1.3)
|
||
|
||
names with external linkage
|
||
|
||
[2](#reserved.names.general-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3141)
|
||
|
||
If a program declares or defines a name in a context where it is
|
||
reserved, other than as explicitly allowed by [[library]](library "16 Library introduction"), its behavior is
|
||
undefined[.](#reserved.names.general-2.sentence-1)
|
||
|
||
#### [16.4.5.3.2](#zombie.names) Zombie names [[zombie.names]](zombie.names)
|
||
|
||
[1](#zombie.names-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3152)
|
||
|
||
In namespace std, the names shown in Table [38](#tab:zombie.names.std "Table 38: Zombie names in namespace std") are
|
||
reserved for previous standardization:
|
||
|
||
Table [38](#tab:zombie.names.std) — Zombie names in namespace std [[tab:zombie.names.std]](./tab:zombie.names.std)
|
||
|
||
| [ð](#tab:zombie.names.std-row-1)<br> auto_ptr | generate_header | pointer_to_binary_function |
|
||
| --- | --- | --- |
|
||
| [ð](#tab:zombie.names.std-row-2)<br> auto_ptr_ref | get_pointer_safety | pointer_to_unary_function |
|
||
| [ð](#tab:zombie.names.std-row-3)<br> binary_function | get_temporary_buffer | ptr_fun |
|
||
| [ð](#tab:zombie.names.std-row-4)<br> binary_negate | get_unexpected | random_shuffle |
|
||
| [ð](#tab:zombie.names.std-row-5)<br> bind1st | gets | raw_storage_iterator |
|
||
| [ð](#tab:zombie.names.std-row-6)<br> bind2nd | is_literal_type | result_of |
|
||
| [ð](#tab:zombie.names.std-row-7)<br> binder1st | is_literal_type_v | result_of_t |
|
||
| [ð](#tab:zombie.names.std-row-8)<br> binder2nd | istrstream | return_temporary_buffer |
|
||
| [ð](#tab:zombie.names.std-row-9)<br> codecvt_mode | little_endian | set_unexpected |
|
||
| [ð](#tab:zombie.names.std-row-10)<br> codecvt_utf16 | mem_fun1_ref_t | strstream |
|
||
| [ð](#tab:zombie.names.std-row-11)<br> codecvt_utf8 | mem_fun1_t | strstreambuf |
|
||
| [ð](#tab:zombie.names.std-row-12)<br> codecvt_utf8_utf16 | mem_fun_ref_t | unary_function |
|
||
| [ð](#tab:zombie.names.std-row-13)<br> const_mem_fun1_ref_t | mem_fun_ref | unary_negate |
|
||
| [ð](#tab:zombie.names.std-row-14)<br> const_mem_fun1_t | mem_fun_t | uncaught_exception |
|
||
| [ð](#tab:zombie.names.std-row-15)<br> const_mem_fun_ref_t | mem_fun | undeclare_no_pointers |
|
||
| [ð](#tab:zombie.names.std-row-16)<br> const_mem_fun_t | not1 | undeclare_reachable |
|
||
| [ð](#tab:zombie.names.std-row-17)<br> consume_header | not2 | unexpected_handler |
|
||
| [ð](#tab:zombie.names.std-row-18)<br> declare_no_pointers | ostrstream | wbuffer_convert |
|
||
| [ð](#tab:zombie.names.std-row-19)<br> declare_reachable | pointer_safety | wstring_convert |
|
||
|
||
[2](#zombie.names-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3220)
|
||
|
||
The names shown in Table [39](#tab:zombie.names.objmacro "Table 39: Zombie object-like macros") are reserved as members for
|
||
previous standardization, and may not be used as a name for object-like macros
|
||
in portable code:
|
||
|
||
Table [39](#tab:zombie.names.objmacro) — Zombie object-like macros [[tab:zombie.names.objmacro]](./tab:zombie.names.objmacro)
|
||
|
||
| [ð](#tab:zombie.names.objmacro-row-1)<br> argument_type | op | second_argument_type |
|
||
| --- | --- | --- |
|
||
| [ð](#tab:zombie.names.objmacro-row-2)<br> first_argument_type | open_mode | seek_dir |
|
||
| [ð](#tab:zombie.names.objmacro-row-3)<br> io_state | preferred | strict |
|
||
|
||
[3](#zombie.names-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3241)
|
||
|
||
The names shown in Table [40](#tab:zombie.names.fnmacro "Table 40: Zombie function-like macros") 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](#tab:zombie.names.fnmacro) — Zombie function-like macros [[tab:zombie.names.fnmacro]](./tab:zombie.names.fnmacro)
|
||
|
||
| [ð](#tab:zombie.names.fnmacro-row-1)<br> converted | freeze | from_bytes | pcount | stossc | to_bytes |
|
||
| --- | --- | --- | --- | --- | --- |
|
||
|
||
[4](#zombie.names-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3261)
|
||
|
||
The header names shown in Table [41](#tab:zombie.names.header "Table 41: Zombie headers") are reserved for previous
|
||
standardization:
|
||
|
||
Table [41](#tab:zombie.names.header) — Zombie headers [[tab:zombie.names.header]](./tab:zombie.names.header)
|
||
|
||
| [ð](#tab:zombie.names.header-row-1)<br><ccomplex> | <codecvt> | <cstdbool> | <ctgmath> | <strstream> |
|
||
| --- | --- | --- | --- | --- |
|
||
| [ð](#tab:zombie.names.header-row-2)<br><ciso646> | <cstdalign> | | | |
|
||
|
||
#### [16.4.5.3.3](#macro.names) Macro names [[macro.names]](macro.names)
|
||
|
||
[1](#macro.names-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3282)
|
||
|
||
A translation unit that includes a standard library header shall not#define or #undef names declared in any standard
|
||
library header[.](#macro.names-1.sentence-1)
|
||
|
||
#### [16.4.5.3.4](#extern.names) External linkage [[extern.names]](extern.names)
|
||
|
||
[1](#extern.names-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3291)
|
||
|
||
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](#footnote-152 "The list of such reserved names includes errno, declared or defined in <cerrno>.") both in namespace std and in the global namespace[.](#extern.names-1.sentence-1)
|
||
|
||
[2](#extern.names-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3303)
|
||
|
||
Eachglobal function signature declared withexternal linkage in a header is reserved to the
|
||
implementation to designate that function signature withexternal linkage[.](#extern.names-2.sentence-1)[153](#footnote-153 "The list of such reserved function signatures with external linkage includes setjmp(jmp_buf), declared or defined in <csetjmp>, and va_end(va_list), declared or defined in <cstdarg>.")
|
||
|
||
[3](#extern.names-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3326)
|
||
|
||
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[.](#extern.names-3.sentence-1)
|
||
|
||
[4](#extern.names-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3336)
|
||
|
||
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](#footnote-154 "The function signatures declared in <cuchar>, <cwchar>, and <cwctype> are always reserved, notwithstanding the restrictions imposed in subclause 4.5.1 of Amendment 1 to the C Standard for these headers.") or as a name of namespace scope in the global namespace[.](#extern.names-4.sentence-1)
|
||
|
||
[152)](#footnote-152)[152)](#footnoteref-152)
|
||
|
||
The list of such reserved names includeserrno, declared or defined in [<cerrno>](errno.general#header:%3ccerrno%3e "19.4.1 General [errno.general]")[.](#footnote-152.sentence-1)
|
||
|
||
[153)](#footnote-153)[153)](#footnoteref-153)
|
||
|
||
The list of such reserved function
|
||
signatures with external linkage includessetjmp(jmp_buf),
|
||
declared or defined in [<csetjmp>](csetjmp.syn#header:%3ccsetjmp%3e "17.14.3 Header <csetjmp> synopsis [csetjmp.syn]"),
|
||
andva_end(va_list),
|
||
declared or defined in[<cstdarg>](cstdarg.syn#header:%3ccstdarg%3e "17.14.2 Header <cstdarg> synopsis [cstdarg.syn]")[.](#footnote-153.sentence-1)
|
||
|
||
[154)](#footnote-154)[154)](#footnoteref-154)
|
||
|
||
The function signatures declared in[<cuchar>](cuchar.syn#header:%3ccuchar%3e "28.7.4 Header <cuchar> synopsis [cuchar.syn]"),[<cwchar>](cwchar.syn#header:%3ccwchar%3e "28.7.3 Header <cwchar> synopsis [cwchar.syn]"),
|
||
and[<cwctype>](cwctype.syn#header:%3ccwctype%3e "28.7.2 Header <cwctype> synopsis [cwctype.syn]") are always reserved, notwithstanding the restrictions imposed in subclause
|
||
4.5.1 of Amendment 1 to the C Standard for these headers[.](#footnote-154.sentence-1)
|
||
|
||
#### [16.4.5.3.5](#extern.types) Types [[extern.types]](extern.types)
|
||
|
||
[1](#extern.types-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3362)
|
||
|
||
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[.](#extern.types-1.sentence-1)
|
||
|
||
#### [16.4.5.3.6](#usrlit.suffix) User-defined literal suffixes [[usrlit.suffix]](usrlit.suffix)
|
||
|
||
[1](#usrlit.suffix-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3375)
|
||
|
||
Literal suffix identifiers ([[over.literal]](over.literal "12.6 User-defined literals")) that do not start with an underscore are reserved for future standardization[.](#usrlit.suffix-1.sentence-1)
|
||
|
||
Literal suffix identifiers that contain a double underscore__are reserved for use by C++ implementations[.](#usrlit.suffix-1.sentence-2)
|
||
|
||
#### [16.4.5.4](#alt.headers) Headers [[alt.headers]](alt.headers)
|
||
|
||
[1](#alt.headers-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3384)
|
||
|
||
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](cpp.include "15.3 Source file inclusion [cpp.include]"),
|
||
the behavior is undefined[.](#alt.headers-1.sentence-1)
|
||
|
||
#### [16.4.5.5](#derived.classes) Derived classes [[derived.classes]](derived.classes)
|
||
|
||
[1](#derived.classes-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3395)
|
||
|
||
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]](class.virtual "11.7.3 Virtual functions"))[.](#derived.classes-1.sentence-1)
|
||
|
||
#### [16.4.5.6](#replacement.functions) Replacement functions [[replacement.functions]](replacement.functions)
|
||
|
||
[1](#replacement.functions-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3405)
|
||
|
||
If a function defined in[[support]](support "17 Language support library") through [[exec]](exec "33 Execution control library") and [[depr]](depr "Annex D (normative) Compatibility features") is specified as replaceable ([[dcl.fct.def.replace]](dcl.fct.def.replace#term.replaceable.function "9.6.5 Replaceable function definitions")),
|
||
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[.](#replacement.functions-1.sentence-1)
|
||
|
||
#### [16.4.5.7](#handler.functions) Handler functions [[handler.functions]](handler.functions)
|
||
|
||
[1](#handler.functions-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3415)
|
||
|
||
The C++ standard library provides a default version of the following handler
|
||
function ([[support]](support "17 Language support library")):
|
||
|
||
- [(1.1)](#handler.functions-1.1)
|
||
|
||
terminate_handler
|
||
|
||
[2](#handler.functions-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3424)
|
||
|
||
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):
|
||
|
||
- [(2.1)](#handler.functions-2.1)
|
||
|
||
set_new_handler
|
||
|
||
- [(2.2)](#handler.functions-2.2)
|
||
|
||
set_terminate
|
||
|
||
See also subclauses [[alloc.errors]](alloc.errors "17.6.4 Storage allocation errors"), Storage allocation errors, and [[support.exception]](support.exception "17.9 Exception handling"),
|
||
Exception handling[.](#handler.functions-2.sentence-1)
|
||
|
||
[3](#handler.functions-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3435)
|
||
|
||
A C++ program can get a pointer to the current handler function by calling the following
|
||
functions:
|
||
|
||
- [(3.1)](#handler.functions-3.1)
|
||
|
||
get_new_handler
|
||
|
||
- [(3.2)](#handler.functions-3.2)
|
||
|
||
get_terminate
|
||
|
||
[4](#handler.functions-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3447)
|
||
|
||
Calling the set_* and get_* functions shall not incur a data race ([[intro.races]](intro.races "6.10.2.2 Data races"))[.](#handler.functions-4.sentence-1)
|
||
|
||
A call to any of the set_* functions synchronizes with subsequent calls to the sameset_* function and to the corresponding get_* function[.](#handler.functions-4.sentence-2)
|
||
|
||
#### [16.4.5.8](#res.on.functions) Other functions [[res.on.functions]](res.on.functions)
|
||
|
||
[1](#res.on.functions-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3454)
|
||
|
||
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[.](#res.on.functions-1.sentence-1)
|
||
|
||
If these components do not meet their requirements, this document places no requirements
|
||
on the implementation[.](#res.on.functions-1.sentence-2)
|
||
|
||
[2](#res.on.functions-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3461)
|
||
|
||
In particular, the behavior is undefined in the following cases:
|
||
|
||
- [(2.1)](#res.on.functions-2.1)
|
||
|
||
For replacement functions ([[replacement.functions]](#replacement.functions "16.4.5.6 Replacement functions")), if the installed replacement function does not
|
||
implement the semantics of the applicable*Required behavior*: paragraph[.](#res.on.functions-2.1.sentence-1)
|
||
|
||
- [(2.2)](#res.on.functions-2.2)
|
||
|
||
For handler functions ([[new.handler]](new.handler "17.6.4.3 Type new_handler"), [[terminate.handler]](terminate.handler "17.9.5.1 Type terminate_handler")),
|
||
if the installed handler function does not implement the semantics of the applicable*Required behavior*: paragraph[.](#res.on.functions-2.2.sentence-1)
|
||
|
||
- [(2.3)](#res.on.functions-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]](#allocator.requirements "16.4.4.6 Cpp17Allocator requirements"), [[container.requirements]](container.requirements "23.2 Requirements"), [[iterator.requirements]](iterator.requirements "24.3 Iterator requirements"), [[algorithms.requirements]](algorithms.requirements "26.2 Algorithms requirements"), [[numeric.requirements]](numeric.requirements "29.2 Numeric type requirements"))[.](#res.on.functions-2.3.sentence-1)
|
||
Operations on such types can report a failure by throwing an exception
|
||
unless otherwise specified[.](#res.on.functions-2.3.sentence-2)
|
||
|
||
- [(2.4)](#res.on.functions-2.4)
|
||
|
||
If any replacement function or handler function or destructor operation exits via an exception,
|
||
unless specifically allowed
|
||
in the applicable*Required behavior*: paragraph[.](#res.on.functions-2.4.sentence-1)
|
||
|
||
- [(2.5)](#res.on.functions-2.5)
|
||
|
||
If an incomplete type ([[basic.types.general]](basic.types.general#term.incomplete.type "6.9.1 General")) is used as a template
|
||
argument when instantiating a template component or evaluating a concept, unless specifically
|
||
allowed for that component[.](#res.on.functions-2.5.sentence-1)
|
||
|
||
#### [16.4.5.9](#res.on.arguments) Function arguments [[res.on.arguments]](res.on.arguments)
|
||
|
||
[1](#res.on.arguments-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3496)
|
||
|
||
Each of the following applies to all argumentsto functions defined in the C++ standard library, unless explicitly stated otherwise[.](#res.on.arguments-1.sentence-1)
|
||
|
||
- [(1.1)](#res.on.arguments-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[.](#res.on.arguments-1.1.sentence-1)
|
||
|
||
- [(1.2)](#res.on.arguments-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[.](#res.on.arguments-1.2.sentence-1)
|
||
|
||
- [(1.3)](#res.on.arguments-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]](#lib.types.movedfrom "16.4.6.17 Moved-from state of library types"))[.](#res.on.arguments-1.3.sentence-1)
|
||
[*Note [1](#res.on.arguments-note-1)*:
|
||
If the type of a parameter is a forwarding reference ([[temp.deduct.call]](temp.deduct.call "13.10.3.2 Deducing template arguments from a function call"))
|
||
that is deduced to an lvalue reference type, then
|
||
the argument is not bound to an rvalue reference[.](#res.on.arguments-1.3.sentence-2)
|
||
â *end note*]
|
||
[*Note [2](#res.on.arguments-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[.](#res.on.arguments-1.3.sentence-3)
|
||
The implementation
|
||
is free to optimize away aliasing checks which would possibly be needed if the argument was
|
||
an lvalue[.](#res.on.arguments-1.3.sentence-4)
|
||
â *end note*]
|
||
|
||
#### [16.4.5.10](#res.on.objects) Library object access [[res.on.objects]](res.on.objects)
|
||
|
||
[1](#res.on.objects-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3543)
|
||
|
||
The behavior of a program is undefined if calls to standard library functions from different
|
||
threads may introduce a data race[.](#res.on.objects-1.sentence-1)
|
||
|
||
The conditions under which this may occur are specified
|
||
in [[res.on.data.races]](#res.on.data.races "16.4.6.10 Data race avoidance")[.](#res.on.objects-1.sentence-2)
|
||
|
||
[*Note [1](#res.on.objects-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[.](#res.on.objects-1.sentence-3)
|
||
|
||
â *end note*]
|
||
|
||
[2](#res.on.objects-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3553)
|
||
|
||
If an object of a standard library type is accessed, and
|
||
the beginning of the object's [lifetime](basic.life "6.8.4 Lifetime [basic.life]") 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[.](#res.on.objects-2.sentence-1)
|
||
|
||
[*Note [2](#res.on.objects-note-2)*:
|
||
|
||
This applies even to objects such as mutexes intended for thread synchronization[.](#res.on.objects-2.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
#### [16.4.5.11](#res.on.requirements) Semantic requirements [[res.on.requirements]](res.on.requirements)
|
||
|
||
[1](#res.on.requirements-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3565)
|
||
|
||
A sequence Args of template arguments is said to[*model*](#def:model,concept "16.4.5.11 Semantic requirements [res.on.requirements]") a concept C if Args satisfies C ([[temp.constr.decl]](temp.constr.decl "13.5.3 Constrained declarations")) and
|
||
meets all semantic requirements (if any)
|
||
given in the specification of C[.](#res.on.requirements-1.sentence-1)
|
||
|
||
[2](#res.on.requirements-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3574)
|
||
|
||
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[.](#res.on.requirements-2.sentence-1)
|
||
|
||
[3](#res.on.requirements-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3580)
|
||
|
||
If the semantic requirements of a declaration's
|
||
constraints ([[structure.requirements]](structure.requirements "16.3.2.3 Requirements")) are not modeled at the point of use,
|
||
the program is ill-formed, no diagnostic required[.](#res.on.requirements-3.sentence-1)
|
||
|
||
### [16.4.6](#conforming) Conforming implementations [[conforming]](conforming)
|
||
|
||
#### [16.4.6.1](#conforming.overview) Overview [[conforming.overview]](conforming.overview)
|
||
|
||
[1](#conforming.overview-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3589)
|
||
|
||
Subclause [[conforming]](#conforming "16.4.6 Conforming implementations") describes the constraints upon, and latitude of, implementations of the C++ standard library[.](#conforming.overview-1.sentence-1)
|
||
|
||
[2](#conforming.overview-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3592)
|
||
|
||
An implementation's use of
|
||
|
||
- [(2.1)](#conforming.overview-2.1)
|
||
|
||
headers is discussed in [[res.on.headers]](#res.on.headers "16.4.6.2 Headers"),
|
||
|
||
- [(2.2)](#conforming.overview-2.2)
|
||
|
||
macros in [[res.on.macro.definitions]](#res.on.macro.definitions "16.4.6.3 Restrictions on macro definitions"),
|
||
|
||
- [(2.3)](#conforming.overview-2.3)
|
||
|
||
non-member functions in [[global.functions]](#global.functions "16.4.6.4 Non-member functions"),
|
||
|
||
- [(2.4)](#conforming.overview-2.4)
|
||
|
||
member functions in [[member.functions]](#member.functions "16.4.6.5 Member functions"),
|
||
|
||
- [(2.5)](#conforming.overview-2.5)
|
||
|
||
data race avoidance in [[res.on.data.races]](#res.on.data.races "16.4.6.10 Data race avoidance"),
|
||
|
||
- [(2.6)](#conforming.overview-2.6)
|
||
|
||
access specifiers in [[protection.within.classes]](#protection.within.classes "16.4.6.12 Protection within classes"),
|
||
|
||
- [(2.7)](#conforming.overview-2.7)
|
||
|
||
class derivation in [[derivation]](#derivation "16.4.6.13 Derived classes"),
|
||
|
||
- [(2.8)](#conforming.overview-2.8)
|
||
|
||
exceptions in [[res.on.exception.handling]](#res.on.exception.handling "16.4.6.14 Restrictions on exception handling"), and
|
||
|
||
- [(2.9)](#conforming.overview-2.9)
|
||
|
||
contract assertions in [[res.contract.assertions]](#res.contract.assertions "16.4.6.15 Contract assertions")[.](#conforming.overview-2.sentence-1)
|
||
|
||
#### [16.4.6.2](#res.on.headers) Headers [[res.on.headers]](res.on.headers)
|
||
|
||
[1](#res.on.headers-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3608)
|
||
|
||
A C++ header may include other C++ headers[.](#res.on.headers-1.sentence-1)
|
||
|
||
A C++ header shall provide the declarations and definitions that appear in its
|
||
synopsis[.](#res.on.headers-1.sentence-2)
|
||
|
||
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[.](#res.on.headers-1.sentence-3)
|
||
|
||
[2](#res.on.headers-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3615)
|
||
|
||
Certain types and macros are defined in more than one header[.](#res.on.headers-2.sentence-1)
|
||
|
||
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]](basic.def.odr "6.3 One-definition rule"))[.](#res.on.headers-2.sentence-2)
|
||
|
||
[3](#res.on.headers-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3620)
|
||
|
||
The [C standard library headers](support.c.headers "17.15 C headers [support.c.headers]") shall include only their corresponding C++ standard library header,
|
||
as described in [[headers]](#headers "16.4.2.3 Headers")[.](#res.on.headers-3.sentence-1)
|
||
|
||
#### [16.4.6.3](#res.on.macro.definitions) Restrictions on macro definitions [[res.on.macro.definitions]](res.on.macro.definitions)
|
||
|
||
[1](#res.on.macro.definitions-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3628)
|
||
|
||
The names and global function signatures described in [[contents]](#contents "16.4.2.2 Library contents") are
|
||
reserved to the implementation[.](#res.on.macro.definitions-1.sentence-1)
|
||
|
||
[2](#res.on.macro.definitions-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3637)
|
||
|
||
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[.](#res.on.macro.definitions-2.sentence-1)
|
||
|
||
#### [16.4.6.4](#global.functions) Non-member functions [[global.functions]](global.functions)
|
||
|
||
[1](#global.functions-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3645)
|
||
|
||
It is unspecified whether any
|
||
non-member
|
||
functions in the C++ standard library are defined as[inline](dcl.inline "9.2.8 The inline specifier [dcl.inline]")[.](#global.functions-1.sentence-1)
|
||
|
||
[2](#global.functions-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3651)
|
||
|
||
A call to a non-member function signature
|
||
described in [[support]](support "17 Language support library") through [[exec]](exec "33 Execution control library") and[[depr]](depr "Annex D (normative) Compatibility features") shall behave as if the implementation declared no additional
|
||
non-member function signatures[.](#global.functions-2.sentence-1)[155](#footnote-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.")
|
||
|
||
[3](#global.functions-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3663)
|
||
|
||
An implementation shall not declare a non-member function signature
|
||
with additional default arguments[.](#global.functions-3.sentence-1)
|
||
|
||
[4](#global.functions-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3667)
|
||
|
||
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]](basic.lookup.argdep "6.5.4 Argument-dependent name lookup"))[.](#global.functions-4.sentence-1)
|
||
|
||
[*Note [1](#global.functions-note-1)*:
|
||
|
||
The phrase âunless otherwise specifiedâ applies to cases such as
|
||
the swappable with requirements ([[swappable.requirements]](#swappable.requirements "16.4.4.3 Swappable requirements"))[.](#global.functions-4.sentence-2)
|
||
|
||
The exception for overloaded operators allows argument-dependent lookup
|
||
in cases like that of[ostream_iterator::operator=](ostream.iterator.ops#lib:ostream_iterator,operator= "24.6.3.3 Operations [ostream.iterator.ops]"):
|
||
|
||
*Effects*: **out_stream* << value;if (*delim* != 0)**out_stream* << *delim*;return *this;
|
||
|
||
â *end note*]
|
||
|
||
[155)](#footnote-155)[155)](#footnoteref-155)
|
||
|
||
A valid C++ program always
|
||
calls the expected library non-member function[.](#footnote-155.sentence-1)
|
||
|
||
An implementation can
|
||
also define additional non-member functions that would otherwise not
|
||
be called by a valid C++ program[.](#footnote-155.sentence-2)
|
||
|
||
#### [16.4.6.5](#member.functions) Member functions [[member.functions]](member.functions)
|
||
|
||
[1](#member.functions-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3690)
|
||
|
||
It is unspecified whether any member functions in the C++ standard library are defined as[inline](dcl.inline "9.2.8 The inline specifier [dcl.inline]")[.](#member.functions-1.sentence-1)
|
||
|
||
[2](#member.functions-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3694)
|
||
|
||
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[.](#member.functions-2.sentence-1)
|
||
|
||
[*Note [1](#member.functions-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[.](#member.functions-2.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
#### [16.4.6.6](#hidden.friends) Friend functions [[hidden.friends]](hidden.friends)
|
||
|
||
[1](#hidden.friends-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3709)
|
||
|
||
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[.](#hidden.friends-1.sentence-1)
|
||
|
||
[*Note [1](#hidden.friends-note-1)*:
|
||
|
||
In particular,
|
||
a conforming implementation does not provide
|
||
any additional declarations of that function or function template
|
||
at namespace scope[.](#hidden.friends-1.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
[*Note [2](#hidden.friends-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]](basic.lookup.unqual "6.5.3 Unqualified name lookup")) nor
|
||
to qualified lookup ([[basic.lookup.qual]](basic.lookup.qual "6.5.5 Qualified name lookup"))[.](#hidden.friends-1.sentence-3)
|
||
|
||
â *end note*]
|
||
|
||
#### [16.4.6.7](#constexpr.functions) Constexpr functions and constructors [[constexpr.functions]](constexpr.functions)
|
||
|
||
[1](#constexpr.functions-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3732)
|
||
|
||
This document explicitly requires that certain standard library functions areconstexpr ([[dcl.constexpr]](dcl.constexpr "9.2.6 The constexpr and consteval specifiers"))[.](#constexpr.functions-1.sentence-1)
|
||
|
||
An implementation shall not declare
|
||
any standard library function signature as constexpr except for those where
|
||
it is explicitly required[.](#constexpr.functions-1.sentence-2)
|
||
|
||
Within any header that provides any non-defining declarations of constexpr
|
||
functions or constructors an implementation shall provide corresponding definitions[.](#constexpr.functions-1.sentence-3)
|
||
|
||
#### [16.4.6.8](#algorithm.stable) Requirements for stable algorithms [[algorithm.stable]](algorithm.stable)
|
||
|
||
[1](#algorithm.stable-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3742)
|
||
|
||
When the requirements for an algorithm state that it is âstableâ without further elaboration,
|
||
it means:
|
||
|
||
- [(1.1)](#algorithm.stable-1.1)
|
||
|
||
For the sort algorithms the relative order of equivalent
|
||
elements is preserved[.](#algorithm.stable-1.1.sentence-1)
|
||
|
||
- [(1.2)](#algorithm.stable-1.2)
|
||
|
||
For the remove and copy algorithms the relative order of
|
||
the elements that are not removed is preserved[.](#algorithm.stable-1.2.sentence-1)
|
||
|
||
- [(1.3)](#algorithm.stable-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)[.](#algorithm.stable-1.3.sentence-1)
|
||
|
||
#### [16.4.6.9](#reentrancy) Reentrancy [[reentrancy]](reentrancy)
|
||
|
||
[1](#reentrancy-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3762)
|
||
|
||
Except where explicitly specified in this document, it is implementation-defined which functions in the C++ standard
|
||
library may be recursively reentered[.](#reentrancy-1.sentence-1)
|
||
|
||
#### [16.4.6.10](#res.on.data.races) Data race avoidance [[res.on.data.races]](res.on.data.races)
|
||
|
||
[1](#res.on.data.races-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3769)
|
||
|
||
This subclause specifies requirements that implementations shall meet to prevent[data races](intro.multithread#def:data_race "6.10.2 Multi-threaded executions and data races [intro.multithread]")[.](#res.on.data.races-1.sentence-1)
|
||
|
||
Every standard library function shall meet each requirement unless otherwise specified[.](#res.on.data.races-1.sentence-2)
|
||
|
||
Implementations may prevent data races in cases other than those specified below[.](#res.on.data.races-1.sentence-3)
|
||
|
||
[2](#res.on.data.races-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3775)
|
||
|
||
A C++ standard library function shall not directly or indirectly access
|
||
objects ([[intro.multithread]](intro.multithread "6.10.2 Multi-threaded executions and data races")) accessible by threads other than the current thread
|
||
unless the objects are accessed directly or indirectly via the function's arguments,
|
||
including this[.](#res.on.data.races-2.sentence-1)
|
||
|
||
[3](#res.on.data.races-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3781)
|
||
|
||
A C++ standard library function shall not directly or indirectly modify
|
||
objects ([[intro.multithread]](intro.multithread "6.10.2 Multi-threaded executions and data races")) 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[.](#res.on.data.races-3.sentence-1)
|
||
|
||
[4](#res.on.data.races-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3787)
|
||
|
||
[*Note [1](#res.on.data.races-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[.](#res.on.data.races-4.sentence-1)
|
||
|
||
â *end note*]
|
||
|
||
[5](#res.on.data.races-5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3794)
|
||
|
||
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[.](#res.on.data.races-5.sentence-1)
|
||
|
||
[6](#res.on.data.races-6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3799)
|
||
|
||
Operations on iterators obtained by calling a standard library container or string
|
||
member function may access the underlying container, but shall not modify it[.](#res.on.data.races-6.sentence-1)
|
||
|
||
[*Note [2](#res.on.data.races-note-2)*:
|
||
|
||
In particular, container operations that invalidate iterators conflict
|
||
with operations on iterators associated with that container[.](#res.on.data.races-6.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
[7](#res.on.data.races-7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3807)
|
||
|
||
Implementations may share their own internal objects between threads if the objects are
|
||
not visible to users and are protected against data races[.](#res.on.data.races-7.sentence-1)
|
||
|
||
[8](#res.on.data.races-8)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3811)
|
||
|
||
Unless otherwise specified, C++ standard library functions shall perform all operations
|
||
solely within the current thread if those operations have effects that are[visible](intro.multithread#def:side_effects,visible "6.10.2 Multi-threaded executions and data races [intro.multithread]") to users[.](#res.on.data.races-8.sentence-1)
|
||
|
||
[9](#res.on.data.races-9)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3816)
|
||
|
||
[*Note [3](#res.on.data.races-note-3)*:
|
||
|
||
This allows implementations to parallelize operations if there are no visibleside effects[.](#res.on.data.races-9.sentence-1)
|
||
|
||
â *end note*]
|
||
|
||
#### [16.4.6.11](#library.class.props) Properties of library classes [[library.class.props]](library.class.props)
|
||
|
||
[1](#library.class.props-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3825)
|
||
|
||
Unless explicitly stated otherwise, it is unspecified whether any class
|
||
described in [[support]](support "17 Language support library") through [[exec]](exec "33 Execution control library") and[[depr]](depr "Annex D (normative) Compatibility features") is a trivially copyable class, a standard-layout class, or an
|
||
implicit-lifetime class ([[class.prop]](class.prop "11.2 Properties of classes"))[.](#library.class.props-1.sentence-1)
|
||
|
||
[2](#library.class.props-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3831)
|
||
|
||
Unless explicitly stated otherwise, it is unspecified whether any class for
|
||
which trivial relocation (i.e., the effects oftrivially_relocate ([[obj.lifetime]](obj.lifetime "20.2.6 Explicit lifetime management"))) 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]](class.prop "11.2 Properties of classes"))[.](#library.class.props-2.sentence-1)
|
||
|
||
[3](#library.class.props-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3838)
|
||
|
||
Unless explicitly stated otherwise, it is unspecified whether a class C is a replaceable class ([[class.prop]](class.prop "11.2 Properties of classes")) 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[.](#library.class.props-3.sentence-1)
|
||
|
||
#### [16.4.6.12](#protection.within.classes) Protection within classes [[protection.within.classes]](protection.within.classes)
|
||
|
||
[1](#protection.within.classes-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3847)
|
||
|
||
It is unspecified whether any function signature or class described in[[support]](support "17 Language support library") through [[exec]](exec "33 Execution control library") and [[depr]](depr "Annex D (normative) Compatibility features") is a
|
||
friend of another class in the C++ standard library[.](#protection.within.classes-1.sentence-1)
|
||
|
||
#### [16.4.6.13](#derivation) Derived classes [[derivation]](derivation)
|
||
|
||
[1](#derivation-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3856)
|
||
|
||
An implementation may derive any class in the C++ standard library from a class with a
|
||
name reserved to the implementation[.](#derivation-1.sentence-1)
|
||
|
||
[2](#derivation-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3862)
|
||
|
||
Certain classes defined in the C++ standard library are required to be derived from
|
||
other classes
|
||
in the C++ standard library[.](#derivation-2.sentence-1)
|
||
|
||
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[.](#derivation-2.sentence-2)
|
||
|
||
[3](#derivation-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3870)
|
||
|
||
In any case:
|
||
|
||
- [(3.1)](#derivation-3.1)
|
||
|
||
Every base class described asvirtual shall be virtual;
|
||
|
||
- [(3.2)](#derivation-3.2)
|
||
|
||
Every base class not specified asvirtual shall not be virtual;
|
||
|
||
- [(3.3)](#derivation-3.3)
|
||
|
||
Unless explicitly stated otherwise, types with distinct names shall be distinct
|
||
types[.](#derivation-3.sentence-1)
|
||
[*Note [1](#derivation-note-1)*:
|
||
There is an implicit exception to this rule for types that are
|
||
described as synonyms ([[dcl.typedef]](dcl.typedef "9.2.4 The typedef specifier"), [[namespace.udecl]](namespace.udecl "9.10 The using declaration")), such assize_t ([[support.types]](support.types "17.2 Common definitions")) andstreamoff ([[stream.types]](stream.types "31.2.2 Types"))[.](#derivation-3.3.sentence-2)
|
||
â *end note*]
|
||
|
||
[4](#derivation-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3892)
|
||
|
||
All types specified in the C++ standard library shall be non-final types
|
||
unless otherwise specified[.](#derivation-4.sentence-1)
|
||
|
||
#### [16.4.6.14](#res.on.exception.handling) Restrictions on exception handling [[res.on.exception.handling]](res.on.exception.handling)
|
||
|
||
[1](#res.on.exception.handling-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3900)
|
||
|
||
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.pre#nt:handler "14.1 Preamble [except.pre]") ([[except.handle]](except.handle "14.4 Handling an exception")) for the base type[.](#res.on.exception.handling-1.sentence-1)
|
||
|
||
[2](#res.on.exception.handling-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3908)
|
||
|
||
Functions from the C standard library shall not throw exceptions[156](#footnote-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.") except when such a function calls a program-supplied function that throws an
|
||
exception[.](#res.on.exception.handling-2.sentence-1)[157](#footnote-157 "The functions qsort() and bsearch() ([alg.c.library]) meet this condition.")
|
||
|
||
[3](#res.on.exception.handling-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3926)
|
||
|
||
Destructor operations defined in the C++ standard library
|
||
shall not throw exceptions[.](#res.on.exception.handling-3.sentence-1)
|
||
|
||
Every destructor in the C++ standard library shall behave as if it had a
|
||
non-throwing exception specification ([[except.spec]](except.spec "14.5 Exception specifications"))[.](#res.on.exception.handling-3.sentence-2)
|
||
|
||
[4](#res.on.exception.handling-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3932)
|
||
|
||
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[.](#res.on.exception.handling-4.sentence-1)[158](#footnote-158 "In particular, they can report a failure to allocate storage by throwing an exception of type bad_alloc, or a class derived from bad_alloc ([bad.alloc]).")
|
||
|
||
Implementations should
|
||
report errors by throwing exceptions of or derived
|
||
from the standard
|
||
exception classes ([[bad.alloc]](bad.alloc "17.6.4.1 Class bad_alloc"), [[support.exception]](support.exception "17.9 Exception handling"), [[std.exceptions]](std.exceptions "19.2 Exception classes"))[.](#res.on.exception.handling-4.sentence-2)
|
||
|
||
[5](#res.on.exception.handling-5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3952)
|
||
|
||
An implementation may strengthen the
|
||
exception specification
|
||
for a non-virtual function
|
||
by adding a non-throwing exception specification[.](#res.on.exception.handling-5.sentence-1)
|
||
|
||
[156)](#footnote-156)[156)](#footnoteref-156)
|
||
|
||
That is, the C standard library functions can all be treated as if they
|
||
are marked noexcept[.](#footnote-156.sentence-1)
|
||
|
||
This allows implementations to make performance optimizations
|
||
based on the absence of exceptions at runtime[.](#footnote-156.sentence-2)
|
||
|
||
[157)](#footnote-157)[157)](#footnoteref-157)
|
||
|
||
The functionsqsort() andbsearch() ([[alg.c.library]](alg.c.library "26.13 C library algorithms")) meet this condition[.](#footnote-157.sentence-1)
|
||
|
||
[158)](#footnote-158)[158)](#footnoteref-158)
|
||
|
||
In particular, they
|
||
can report a failure to allocate storage by throwing an exception of type[bad_alloc](bad.alloc "17.6.4.1 Class bad_alloc [bad.alloc]"),
|
||
or a class derived frombad_alloc ([[bad.alloc]](bad.alloc "17.6.4.1 Class bad_alloc"))[.](#footnote-158.sentence-1)
|
||
|
||
#### [16.4.6.15](#res.contract.assertions) Contract assertions [[res.contract.assertions]](res.contract.assertions)
|
||
|
||
[1](#res.contract.assertions-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3960)
|
||
|
||
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]](basic.contract "6.11 Contract assertions"), [[structure.specifications]](structure.specifications "16.3.2.4 Detailed specifications"))[.](#res.contract.assertions-1.sentence-1)
|
||
|
||
#### [16.4.6.16](#value.error.codes) Value of error codes [[value.error.codes]](value.error.codes)
|
||
|
||
[1](#value.error.codes-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3969)
|
||
|
||
Certain functions in the C++ standard library report errors via aerror_code ([[syserr.errcode.overview]](syserr.errcode.overview "19.5.4.1 Overview")) object[.](#value.error.codes-1.sentence-1)
|
||
|
||
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[.](#value.error.codes-1.sentence-2)
|
||
|
||
The implementation shall define the possible values of value() for each of these
|
||
error categories[.](#value.error.codes-1.sentence-3)
|
||
|
||
[*Example [1](#value.error.codes-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[.](#value.error.codes-1.sentence-4)
|
||
|
||
Implementations for operating systems that are not
|
||
based on POSIX should define values identical to the operating system's
|
||
values[.](#value.error.codes-1.sentence-5)
|
||
|
||
For errors that do not originate from the operating system, the implementation
|
||
may provide enums for the associated values[.](#value.error.codes-1.sentence-6)
|
||
|
||
â *end example*]
|
||
|
||
#### [16.4.6.17](#lib.types.movedfrom) Moved-from state of library types [[lib.types.movedfrom]](lib.types.movedfrom)
|
||
|
||
[1](#lib.types.movedfrom-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3990)
|
||
|
||
Objects of types defined in the C++ standard library may be moved
|
||
from ([[class.copy.ctor]](class.copy.ctor "11.4.5.3 Copy/move constructors"))[.](#lib.types.movedfrom-1.sentence-1)
|
||
|
||
Move operations may be explicitly specified or
|
||
implicitly generated[.](#lib.types.movedfrom-1.sentence-2)
|
||
|
||
Unless otherwise specified, such moved-from objects shall
|
||
be placed in a valid but unspecified state ([[defns.valid]](defns.valid "3.67 valid but unspecified state"))[.](#lib.types.movedfrom-1.sentence-3)
|
||
|
||
[2](#lib.types.movedfrom-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lib-intro.tex#L3996)
|
||
|
||
An object of a type defined in the C++ standard library may be
|
||
move-assigned ([[class.copy.assign]](class.copy.assign "11.4.6 Copy/move assignment operator")) to itself[.](#lib.types.movedfrom-2.sentence-1)
|
||
|
||
Unless otherwise specified, such an assignment places the object in
|
||
a valid but unspecified state[.](#lib.types.movedfrom-2.sentence-2)
|