- tmp/tmpr6bf7_an/{from.md → to.md} +552 -446
tmp/tmpr6bf7_an/{from.md → to.md}
RENAMED
|
@@ -1,11 +1,10 @@
|
|
| 1 |
## Library-wide requirements <a id="requirements">[[requirements]]</a>
|
| 2 |
|
| 3 |
-
This subclause specifies requirements that apply to the entire
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
within the library.
|
| 7 |
|
| 8 |
Requirements specified in terms of interactions between threads do not
|
| 9 |
apply to programs having only a single thread of execution.
|
| 10 |
|
| 11 |
Within this subclause, [[organization]] describes the library’s contents
|
|
@@ -15,103 +14,85 @@ constraints on types and functions used with the C++standard library,
|
|
| 15 |
[[constraints]] describes constraints on well-formed C++ programs, and
|
| 16 |
[[conforming]] describes constraints on conforming implementations.
|
| 17 |
|
| 18 |
### Library contents and organization <a id="organization">[[organization]]</a>
|
| 19 |
|
| 20 |
-
[[contents]] describes the entities and macros defined in the
|
| 21 |
-
|
| 22 |
some constraints on those headers. [[compliance]] lists requirements for
|
| 23 |
a freestanding implementation of the C++ standard library.
|
| 24 |
|
| 25 |
#### Library contents <a id="contents">[[contents]]</a>
|
| 26 |
|
| 27 |
-
The C++standard library provides definitions for the entities and
|
| 28 |
-
described in the synopses of the C++standard library headers
|
| 29 |
-
[[headers]]
|
| 30 |
|
| 31 |
All library entities except `operator new` and `operator delete` are
|
| 32 |
defined within the namespace `std` or namespaces nested within namespace
|
| 33 |
`std`.[^12] It is unspecified whether names declared in a specific
|
| 34 |
namespace are declared directly in that namespace or in an inline
|
| 35 |
namespace inside that namespace.[^13]
|
| 36 |
|
| 37 |
Whenever a name `x` defined in the standard library is mentioned, the
|
| 38 |
name `x` is assumed to be fully qualified as `::std::x`, unless
|
| 39 |
-
explicitly described otherwise. For example, if the *Effects:*
|
| 40 |
for library function `F` is described as calling library function `G`,
|
| 41 |
the function `::std::G` is meant.
|
| 42 |
|
| 43 |
#### Headers <a id="headers">[[headers]]</a>
|
| 44 |
|
| 45 |
Each element of the C++ standard library is declared or defined (as
|
| 46 |
appropriate) in a *header*.[^14]
|
| 47 |
|
| 48 |
The C++ standard library provides the *C++ library headers*, shown in
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
**Table: C++library headers** <a id="tab:cpp.library.headers">[tab:cpp.library.headers]</a>
|
| 52 |
-
|
| 53 |
-
| | | | |
|
| 54 |
-
| ---------------------- | -------------------- | -------------------- | ----------------- |
|
| 55 |
-
| `<algorithm>` | `<future>` | `<numeric>` | `<strstream>` |
|
| 56 |
-
| `<any>` | `<initializer_list>` | `<optional>` | `<system_error>` |
|
| 57 |
-
| `<array>` | `<iomanip>` | `<ostream>` | `<thread>` |
|
| 58 |
-
| `<atomic>` | `<ios>` | `<queue>` | `<tuple>` |
|
| 59 |
-
| `<bitset>` | `<iosfwd>` | `<random>` | `<type_traits>` |
|
| 60 |
-
| `<chrono>` | `<iostream>` | `<ratio>` | `<typeindex>` |
|
| 61 |
-
| `<codecvt>` | `<istream>` | `<regex>` | `<typeinfo>` |
|
| 62 |
-
| `<complex>` | `<iterator>` | `<scoped_allocator>` | `<unordered_map>` |
|
| 63 |
-
| `<condition_variable>` | `<limits>` | `<set>` | `<unordered_set>` |
|
| 64 |
-
| `<deque>` | `<list>` | `<shared_mutex>` | `<utility>` |
|
| 65 |
-
| `<exception>` | `<locale>` | `<sstream>` | `<valarray>` |
|
| 66 |
-
| `<execution>` | `<map>` | `<stack>` | `<variant>` |
|
| 67 |
-
| `<filesystem>` | `<memory>` | `<stdexcept>` | `<vector>` |
|
| 68 |
-
| `<forward_list>` | `<memory_resource>` | `<streambuf>` | |
|
| 69 |
-
| `<fstream>` | `<mutex>` | `<string>` | |
|
| 70 |
-
| `<functional>` | `<new>` | `<string_view>` | |
|
| 71 |
-
|
| 72 |
|
| 73 |
The facilities of the C standard library are provided in the additional
|
| 74 |
-
headers shown in
|
| 75 |
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
| `<cassert>` | `<cinttypes>` | `<csignal>` | `<cstdio>` | `<cwchar>` |
|
| 81 |
-
| `<ccomplex>` | `<ciso646>` | `<cstdalign>` | `<cstdlib>` | `<cwctype>` |
|
| 82 |
-
| `<cctype>` | `<climits>` | `<cstdarg>` | `<cstring>` | |
|
| 83 |
-
| `<cerrno>` | `<clocale>` | `<cstdbool>` | `<ctgmath>` | |
|
| 84 |
-
| `<cfenv>` | `<cmath>` | `<cstddef>` | `<ctime>` | |
|
| 85 |
-
| `<cfloat>` | `<csetjmp>` | `<cstdint>` | `<cuchar>` | |
|
| 86 |
|
|
|
|
| 87 |
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
Names which are defined as macros in C shall be defined as macros in the
|
| 101 |
C++ standard library, even if C grants license for implementation as
|
| 102 |
functions.
|
| 103 |
|
| 104 |
-
[*Note
|
| 105 |
`assert`, `offsetof`, `setjmp`, `va_arg`, `va_end`, and
|
| 106 |
`va_start`. — *end note*]
|
| 107 |
|
| 108 |
Names that are defined as functions in C shall be defined as functions
|
| 109 |
in the C++ standard library.[^16]
|
| 110 |
|
| 111 |
-
Identifiers that are keywords or operators in C++shall not be defined
|
| 112 |
-
macros in C++standard library headers.[^17]
|
| 113 |
|
| 114 |
[[depr.c.headers]], C standard library headers, describes the effects of
|
| 115 |
using the `name.h` (C header) form in a C++ program.[^18]
|
| 116 |
|
| 117 |
Annex K of the C standard describes a large number of functions, with
|
|
@@ -122,115 +103,103 @@ service as the C library function with the unsuffixed name, but
|
|
| 122 |
generally take an additional argument whose value is the size of the
|
| 123 |
result array. If any C++ header is included, it is
|
| 124 |
*implementation-defined* whether any of these names is declared in the
|
| 125 |
global namespace. (None of them is declared in namespace `std`.)
|
| 126 |
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
**Table: C standard Annex K names** <a id="tab:c.annex.k.names">[tab:c.annex.k.names]</a>
|
| 132 |
-
|
| 133 |
-
| | | | |
|
| 134 |
-
| ---------------------- | -------------------------- | -------------- | ------------- |
|
| 135 |
-
| `abort_handler_s` | `mbstowcs_s` | `strncat_s` | `vswscanf_s` |
|
| 136 |
-
| `asctime_s` | `memcpy_s` | `strncpy_s` | `vwprintf_s` |
|
| 137 |
-
| `bsearch_s` | `memmove_s` | `strtok_s` | `vwscanf_s` |
|
| 138 |
-
| `constraint_handler_t` | `memset_s` | `swprintf_s` | `wcrtomb_s` |
|
| 139 |
-
| `ctime_s` | `printf_s` | `swscanf_s` | `wcscat_s` |
|
| 140 |
-
| `errno_t` | `qsort_s` | `tmpfile_s` | `wcscpy_s` |
|
| 141 |
-
| `fopen_s` | `RSIZE_MAX` | `TMP_MAX_S` | `wcsncat_s` |
|
| 142 |
-
| `fprintf_s` | `rsize_t` | `tmpnam_s` | `wcsncpy_s` |
|
| 143 |
-
| `freopen_s` | `scanf_s` | `vfprintf_s` | `wcsnlen_s` |
|
| 144 |
-
| `fscanf_s` | `set_constraint_handler_s` | `vfscanf_s` | `wcsrtombs_s` |
|
| 145 |
-
| `fwprintf_s` | `snprintf_s` | `vfwprintf_s` | `wcstok_s` |
|
| 146 |
-
| `fwscanf_s` | `snwprintf_s` | `vfwscanf_s` | `wcstombs_s` |
|
| 147 |
-
| `getenv_s` | `sprintf_s` | `vprintf_s` | `wctomb_s` |
|
| 148 |
-
| `gets_s` | `sscanf_s` | `vscanf_s` | `wmemcpy_s` |
|
| 149 |
-
| `gmtime_s` | `strcat_s` | `vsnprintf_s` | `wmemmove_s` |
|
| 150 |
-
| `ignore_handler_s` | `strcpy_s` | `vsnwprintf_s` | `wprintf_s` |
|
| 151 |
-
| `L_tmpnam_s` | `strerror_s` | `vsprintf_s` | `wscanf_s` |
|
| 152 |
-
| `localtime_s` | `strerrorlen_s` | `vsscanf_s` | |
|
| 153 |
-
| `mbsrtowcs_s` | `strlen_s` | `vswprintf_s` | |
|
| 154 |
-
|
| 155 |
|
| 156 |
#### Freestanding implementations <a id="compliance">[[compliance]]</a>
|
| 157 |
|
| 158 |
-
Two kinds of implementations are defined: *hosted* and *freestanding*
|
| 159 |
-
[[intro.compliance]]
|
| 160 |
-
|
|
|
|
| 161 |
|
| 162 |
A freestanding implementation has an *implementation-defined* set of
|
| 163 |
-
headers. This set shall include at least the headers shown in
|
| 164 |
-
[[
|
| 165 |
|
| 166 |
-
**Table: C++headers for freestanding implementations** <a id="
|
| 167 |
|
| 168 |
| Subclause | | Header |
|
| 169 |
-
| --------------------------------------------- | -------------------------
|
| 170 |
-
| | | `<ciso646>` |
|
| 171 |
| [[support.types]] | Types | `<cstddef>` |
|
| 172 |
-
| [[support.limits]]
|
| 173 |
| [[cstdint]] | Integer types | `<cstdint>` |
|
| 174 |
| [[support.start.term]] | Start and termination | `<cstdlib>` |
|
| 175 |
| [[support.dynamic]] | Dynamic memory management | `<new>` |
|
| 176 |
| [[support.rtti]] | Type identification | `<typeinfo>` |
|
|
|
|
| 177 |
| [[support.exception]] | Exception handling | `<exception>` |
|
| 178 |
| [[support.initlist]] | Initializer lists | `<initializer_list>` |
|
|
|
|
|
|
|
| 179 |
| [[support.runtime]] | Other runtime support | `<cstdarg>` |
|
|
|
|
| 180 |
| [[meta]] | Type traits | `<type_traits>` |
|
|
|
|
| 181 |
| [[atomics]] | Atomics | `<atomic>` |
|
| 182 |
-
| [[depr.cstdalign.syn]], [[depr.cstdbool.syn]] | Deprecated headers | `<cstdalign>` `<cstdbool>` |
|
| 183 |
|
| 184 |
|
| 185 |
The supplied version of the header `<cstdlib>` shall declare at least
|
| 186 |
the functions `abort`, `atexit`, `at_quick_exit`, `exit`, and
|
| 187 |
-
`quick_exit`
|
| 188 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
|
| 190 |
### Using the library <a id="using">[[using]]</a>
|
| 191 |
|
| 192 |
#### Overview <a id="using.overview">[[using.overview]]</a>
|
| 193 |
|
| 194 |
-
|
| 195 |
-
of the C++standard library. [[using.headers]] describes
|
| 196 |
-
translation phase 4, while [[using.linkage]] describes
|
| 197 |
-
phase 8
|
| 198 |
|
| 199 |
#### Headers <a id="using.headers">[[using.headers]]</a>
|
| 200 |
|
| 201 |
The entities in the C++ standard library are defined in headers, whose
|
| 202 |
contents are made available to a translation unit when it contains the
|
| 203 |
-
appropriate `#include` preprocessing directive
|
|
|
|
| 204 |
|
| 205 |
-
A translation unit may include library headers in any order
|
| 206 |
-
[[lex]]
|
| 207 |
-
from being included exactly once, except that the effect of
|
| 208 |
-
either `<cassert>` or `<assert.h>` depends each time on the
|
| 209 |
-
current definition of `NDEBUG`.[^19]
|
| 210 |
|
| 211 |
A translation unit shall include a header only outside of any
|
| 212 |
-
declaration or definition
|
| 213 |
-
|
| 214 |
-
|
|
|
|
|
|
|
| 215 |
|
| 216 |
#### Linkage <a id="using.linkage">[[using.linkage]]</a>
|
| 217 |
|
| 218 |
-
Entities in the C++standard library have external linkage
|
| 219 |
-
[[basic.link]]
|
| 220 |
-
the default `extern "C++"` linkage
|
| 221 |
|
| 222 |
Whether a name from the C standard library declared with external
|
| 223 |
linkage has `extern "C"` or `extern "C++"` linkage is
|
| 224 |
*implementation-defined*. It is recommended that an implementation use
|
| 225 |
`extern "C++"` linkage for this purpose.[^20]
|
| 226 |
|
| 227 |
-
Objects and functions defined in the library and required by a
|
| 228 |
-
|
| 229 |
|
| 230 |
-
See also replacement functions
|
| 231 |
-
changes
|
| 232 |
|
| 233 |
### Requirements on types and expressions <a id="utility.requirements">[[utility.requirements]]</a>
|
| 234 |
|
| 235 |
[[utility.arg.requirements]] describes requirements on types and
|
| 236 |
expressions used to instantiate templates defined in the C++ standard
|
|
@@ -244,74 +213,74 @@ allocators.
|
|
| 244 |
|
| 245 |
#### Template argument requirements <a id="utility.arg.requirements">[[utility.arg.requirements]]</a>
|
| 246 |
|
| 247 |
The template definitions in the C++ standard library refer to various
|
| 248 |
named requirements whose details are set out in Tables
|
| 249 |
-
[[tab:equalitycomparable]]– [[tab:destructible]]. In these
|
| 250 |
-
is an object or reference type to be supplied by a C++
|
| 251 |
-
instantiating a template; `a`, `b`, and `c` are values of type
|
| 252 |
-
`const`) `T`; `s` and `t` are modifiable lvalues of type `T`;
|
| 253 |
-
denotes an identifier; `rv` is an rvalue of type `T`; and `v` is an
|
| 254 |
lvalue of type (possibly `const`) `T` or an rvalue of type `const T`.
|
| 255 |
|
| 256 |
In general, a default constructor is not required. Certain container
|
| 257 |
class member function signatures specify `T()` as a default argument.
|
| 258 |
-
`T()` shall be a well-defined expression
|
| 259 |
-
signatures is called using the default argument
|
| 260 |
|
| 261 |
-
**Table:
|
| 262 |
|
| 263 |
| Expression | Return type |
|
| 264 |
| ---------- | ----------- |
|
| 265 |
| `a == b` | convertible to `bool` | `==` is an equivalence relation, that is, it has the following properties: For all `a`, `a == a`.; If `a == b`, then `b == a`.; If `a == b` and `b == c`, then `a == c`. |
|
| 266 |
|
| 267 |
-
|
|
|
|
| 268 |
|
| 269 |
| Expression | Return type | Requirement |
|
| 270 |
-
| ---------- | --------------------- | ------------------------------------------------------
|
| 271 |
-
| `a < b` | convertible to `bool` | `<` is a strict weak ordering relation
|
| 272 |
|
| 273 |
-
|
|
|
|
| 274 |
|
| 275 |
| Expression | Post-condition |
|
| 276 |
| -------------- | ------------------------------------------------------------------- |
|
| 277 |
| `T t;` | object `t` is default-initialized |
|
| 278 |
| `T u{};` | object `u` is value-initialized or aggregate-initialized |
|
| 279 |
| `T()`<br>`T{}` | an object of type `T` is value-initialized or aggregate-initialized |
|
| 280 |
|
|
|
|
| 281 |
[*Note 1*: `rv` must still meet the requirements of the library
|
| 282 |
component that is using it. The operations listed in those requirements
|
| 283 |
must work as specified whether `rv` has been moved from or
|
| 284 |
not. — *end note*]
|
| 285 |
|
| 286 |
-
**Table:
|
| 287 |
|
| 288 |
| Expression | Post-condition |
|
| 289 |
| ---------- | --------------------------------------------------------- |
|
| 290 |
| `T u = v;` | the value of `v` is unchanged and is equivalent to ` u` |
|
| 291 |
| `T(v)` | the value of `v` is unchanged and is equivalent to `T(v)` |
|
| 292 |
|
|
|
|
| 293 |
[*Note 2*: `rv` must still meet the requirements of the library
|
| 294 |
component that is using it, whether or not `t` and `rv` refer to the
|
| 295 |
same object. The operations listed in those requirements must work as
|
| 296 |
specified whether `rv` has been moved from or not. — *end note*]
|
| 297 |
|
| 298 |
-
**Table:
|
| 299 |
|
| 300 |
| Expression | Return type | Return value | Post-condition |
|
| 301 |
| ---------- | ----------- | ------------ | ------------------------------------------------------- |
|
| 302 |
| `t = v` | `T&` | `t` | `t` is equivalent to `v`, the value of `v` is unchanged |
|
| 303 |
|
| 304 |
|
| 305 |
-
**
|
|
|
|
| 306 |
|
| 307 |
-
|
| 308 |
-
| ---------- | --------------------------------------------------------------------- |
|
| 309 |
-
| `u.~T()` | All resources owned by `u` are reclaimed, no exception is propagated. |
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
#### `Swappable` requirements <a id="swappable.requirements">[[swappable.requirements]]</a>
|
| 313 |
|
| 314 |
This subclause provides definitions for swappable types and expressions.
|
| 315 |
In these definitions, let `t` denote an expression of type `T`, and let
|
| 316 |
`u` denote an expression of type `U`.
|
| 317 |
|
|
@@ -324,16 +293,15 @@ An object `t` is *swappable with* an object `u` if and only if:
|
|
| 324 |
and
|
| 325 |
- the object referred to by `u` has the value originally held by `t`.
|
| 326 |
|
| 327 |
The context in which `swap(t, u)` and `swap(u, t)` are evaluated shall
|
| 328 |
ensure that a binary non-member function named “swap” is selected via
|
| 329 |
-
overload resolution
|
| 330 |
|
| 331 |
-
- the two `swap` function templates defined in `<utility>`
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
[[basic.lookup.argdep]]).
|
| 335 |
|
| 336 |
[*Note 1*: If `T` and `U` are both fundamental types or arrays of
|
| 337 |
fundamental types and the declarations from the header `<utility>` are
|
| 338 |
in scope, the overall lookup set described above is equivalent to that
|
| 339 |
of the qualified name lookup applied to the expression `std::swap(t, u)`
|
|
@@ -344,14 +312,13 @@ swappable requirement includes the header `<utility>` to ensure an
|
|
| 344 |
appropriate evaluation context. — *end note*]
|
| 345 |
|
| 346 |
An rvalue or lvalue `t` is *swappable* if and only if `t` is swappable
|
| 347 |
with any rvalue or lvalue, respectively, of type `T`.
|
| 348 |
|
| 349 |
-
A type `X`
|
| 350 |
-
[[iterator.requirements]]
|
| 351 |
-
|
| 352 |
-
`*x` is swappable.
|
| 353 |
|
| 354 |
[*Example 1*:
|
| 355 |
|
| 356 |
User code can ensure that the evaluation of `swap` calls is performed in
|
| 357 |
an appropriate context under the various conditions as follows:
|
|
@@ -369,12 +336,12 @@ void value_swap(T&& t, U&& u) {
|
|
| 369 |
|
| 370 |
// Requires: lvalues of T shall be swappable.
|
| 371 |
template<class T>
|
| 372 |
void lv_swap(T& t1, T& t2) {
|
| 373 |
using std::swap;
|
| 374 |
-
swap(t1, t2); // OK: uses swappable conditions for
|
| 375 |
-
}
|
| 376 |
|
| 377 |
namespace N {
|
| 378 |
struct A { int m; };
|
| 379 |
struct Proxy { A* a; };
|
| 380 |
Proxy proxy(A& a) { return Proxy{ &a }; }
|
|
@@ -397,103 +364,102 @@ int main() {
|
|
| 397 |
}
|
| 398 |
```
|
| 399 |
|
| 400 |
— *end example*]
|
| 401 |
|
| 402 |
-
####
|
| 403 |
|
| 404 |
-
A
|
| 405 |
-
values. A type `P` meets the requirements
|
| 406 |
|
| 407 |
-
- `P`
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
- lvalues of type `P` are swappable
|
| 411 |
-
- the expressions shown in
|
| 412 |
-
|
| 413 |
-
- `P`
|
| 414 |
|
| 415 |
A value-initialized object of type `P` produces the null value of the
|
| 416 |
type. The null value shall be equivalent only to itself. A
|
| 417 |
default-initialized object of type `P` may have an indeterminate value.
|
| 418 |
|
| 419 |
[*Note 1*: Operations involving indeterminate values may cause
|
| 420 |
undefined behavior. — *end note*]
|
| 421 |
|
| 422 |
An object `p` of type `P` can be contextually converted to `bool`
|
| 423 |
-
|
| 424 |
-
|
| 425 |
|
| 426 |
-
No operation which is part of the
|
| 427 |
-
exit via an exception.
|
| 428 |
|
| 429 |
-
In
|
| 430 |
-
|
| 431 |
-
|
| 432 |
`const`) `std::nullptr_t`.
|
| 433 |
|
| 434 |
-
**Table:
|
| 435 |
|
| 436 |
-
|
|
| 437 |
-
| -------------- | ---------------------------------- | ---------------------------
|
| 438 |
-
| `P u(np);`<br> | |
|
| 439 |
| `P u = np;` | | |
|
| 440 |
-
| `P(np)` | |
|
| 441 |
-
| `t = np` | `P&` |
|
| 442 |
| `a != b` | contextually convertible to `bool` | `!(a == b)` |
|
| 443 |
| `a == np` | contextually convertible to `bool` | `a == P()` |
|
| 444 |
| `np == a` | | |
|
| 445 |
| `a != np` | contextually convertible to `bool` | `!(a == np)` |
|
| 446 |
| `np != a` | | |
|
| 447 |
|
| 448 |
|
| 449 |
-
####
|
| 450 |
|
| 451 |
-
A type `H` meets the
|
| 452 |
|
| 453 |
-
- it is a function object type
|
| 454 |
-
- it
|
| 455 |
-
|
| 456 |
-
- the expressions shown in
|
| 457 |
indicated semantics.
|
| 458 |
|
| 459 |
Given `Key` is an argument type for function objects of type `H`, in
|
| 460 |
-
|
| 461 |
-
|
| 462 |
(possibly `const`) `Key`.
|
| 463 |
|
| 464 |
[*Note 1*: Thus all evaluations of the expression `h(k)` with the same
|
| 465 |
value for `k` yield the same result for a given execution of the
|
| 466 |
program. — *end note*]
|
| 467 |
|
| 468 |
-
####
|
| 469 |
|
| 470 |
The library describes a standard set of requirements for *allocators*,
|
| 471 |
which are class-type objects that encapsulate the information about an
|
| 472 |
allocation model. This information includes the knowledge of pointer
|
| 473 |
types, the type of their difference, the type of the size of objects in
|
| 474 |
this allocation model, as well as the memory allocation and deallocation
|
| 475 |
-
primitives for it. All of the string types
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
|
| 480 |
-
The class template `allocator_traits`
|
| 481 |
-
uniform interface to all allocator types.
|
| 482 |
-
describes the types manipulated through allocators.
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
of `allocator_traits` may provide different defaults and may provide
|
| 491 |
defaults for different requirements than the primary template. Within
|
| 492 |
-
Tables [[tab:
|
| 493 |
-
|
| 494 |
-
|
| 495 |
|
| 496 |
[*Note 1*: If `n == 0`, the return value is unspecified. — *end note*]
|
| 497 |
|
| 498 |
Note A: The member class template `rebind` in the table above is
|
| 499 |
effectively a typedef template.
|
|
@@ -509,29 +475,36 @@ and `Allocator` does not supply a `rebind` member template, the standard
|
|
| 509 |
`allocator_traits` template uses `SomeAllocator<U, Args>` in place of
|
| 510 |
`Allocator::{}rebind<U>::other` by default. For allocator types that are
|
| 511 |
not template instantiations of the above form, no default is provided.
|
| 512 |
|
| 513 |
Note B: If `X::propagate_on_container_copy_assignment::value` is `true`,
|
| 514 |
-
`X` shall
|
| 515 |
-
[[
|
| 516 |
exceptions. If `X::propagate_on_container_move_assignment::value` is
|
| 517 |
-
`true`, `X` shall
|
| 518 |
-
[[
|
| 519 |
exceptions. If `X::propagate_on_container_swap::value` is `true`,
|
| 520 |
-
lvalues of type `X` shall be swappable
|
| 521 |
the `swap` operation shall not throw exceptions.
|
| 522 |
|
| 523 |
-
An allocator type `X` shall
|
| 524 |
-
|
| 525 |
`X::const_pointer`, `X::void_pointer`, and `X::const_void_pointer` types
|
| 526 |
-
shall
|
| 527 |
-
[[
|
| 528 |
-
|
| 529 |
shall exit via an exception. `X::pointer` and `X::const_pointer` shall
|
| 530 |
-
also
|
| 531 |
-
[[random.access.iterators]]
|
| 532 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 533 |
|
| 534 |
Let `x1` and `x2` denote objects of (possibly different) types
|
| 535 |
`X::void_pointer`, `X::const_void_pointer`, `X::pointer`, or
|
| 536 |
`X::const_pointer`. Then, `x1` and `x2` are *equivalently-valued*
|
| 537 |
pointer values, if and only if both `x1` and `x2` can be explicitly
|
|
@@ -570,25 +543,32 @@ An allocator may constrain the types on which it can be instantiated and
|
|
| 570 |
the arguments for which its `construct` or `destroy` members may be
|
| 571 |
called. If a type cannot be used with a particular allocator, the
|
| 572 |
allocator class or the call to `construct` or `destroy` may fail to
|
| 573 |
instantiate.
|
| 574 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 575 |
[*Example 1*:
|
| 576 |
|
| 577 |
The following is an allocator class template supporting the minimal
|
| 578 |
-
interface that
|
| 579 |
-
[[tab:utilities.allocator.requirements]]:
|
| 580 |
|
| 581 |
``` cpp
|
| 582 |
template<class Tp>
|
| 583 |
struct SimpleAllocator {
|
| 584 |
typedef Tp value_type;
|
| 585 |
SimpleAllocator(ctor args);
|
| 586 |
|
| 587 |
template<class T> SimpleAllocator(const SimpleAllocator<T>& other);
|
| 588 |
|
| 589 |
-
Tp* allocate(std::size_t n);
|
| 590 |
void deallocate(Tp* p, std::size_t n);
|
| 591 |
};
|
| 592 |
|
| 593 |
template<class T, class U>
|
| 594 |
bool operator==(const SimpleAllocator<T>&, const SimpleAllocator<U>&);
|
|
@@ -596,52 +576,51 @@ template <class T, class U>
|
|
| 596 |
bool operator!=(const SimpleAllocator<T>&, const SimpleAllocator<U>&);
|
| 597 |
```
|
| 598 |
|
| 599 |
— *end example*]
|
| 600 |
|
| 601 |
-
If the alignment associated with a specific over-aligned type is not
|
| 602 |
-
supported by an allocator, instantiation of the allocator for that type
|
| 603 |
-
may fail. The allocator also may silently ignore the requested
|
| 604 |
-
alignment.
|
| 605 |
-
|
| 606 |
-
[*Note 3*: Additionally, the member function `allocate` for that type
|
| 607 |
-
may fail by throwing an object of type `bad_alloc`. — *end note*]
|
| 608 |
-
|
| 609 |
##### Allocator completeness requirements <a id="allocator.requirements.completeness">[[allocator.requirements.completeness]]</a>
|
| 610 |
|
| 611 |
-
If `X` is an allocator class for type `T`, `X` additionally
|
| 612 |
-
|
| 613 |
-
|
| 614 |
|
| 615 |
- `X` is a complete type, and
|
| 616 |
-
- all the member types of `allocator_traits<X>`
|
| 617 |
other than `value_type` are complete types.
|
| 618 |
|
| 619 |
### Constraints on programs <a id="constraints">[[constraints]]</a>
|
| 620 |
|
| 621 |
#### Overview <a id="constraints.overview">[[constraints.overview]]</a>
|
| 622 |
|
| 623 |
-
|
| 624 |
-
facilities of the C++standard library. The following subclauses
|
| 625 |
-
constraints on the program’s use of namespaces
|
| 626 |
-
use of various reserved names
|
| 627 |
-
headers
|
| 628 |
-
classes
|
| 629 |
-
functions
|
| 630 |
-
functions during execution
|
| 631 |
|
| 632 |
#### Namespace use <a id="namespace.constraints">[[namespace.constraints]]</a>
|
| 633 |
|
| 634 |
##### Namespace `std` <a id="namespace.std">[[namespace.std]]</a>
|
| 635 |
|
| 636 |
-
|
| 637 |
-
definitions to namespace `std` or to a
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 643 |
|
| 644 |
The behavior of a C++ program is undefined if it declares
|
| 645 |
|
| 646 |
- an explicit specialization of any member function of a standard
|
| 647 |
library class template, or
|
|
@@ -649,33 +628,62 @@ The behavior of a C++program is undefined if it declares
|
|
| 649 |
standard library class or class template, or
|
| 650 |
- an explicit or partial specialization of any member class template of
|
| 651 |
a standard library class or class template, or
|
| 652 |
- a deduction guide for any standard library class template.
|
| 653 |
|
| 654 |
-
A program may explicitly instantiate a template defined in the
|
| 655 |
-
library only if the declaration depends on the name of
|
| 656 |
-
type and the instantiation meets the
|
| 657 |
-
the original template.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 658 |
|
| 659 |
A translation unit shall not declare namespace `std` to be an inline
|
| 660 |
-
namespace
|
| 661 |
|
| 662 |
##### Namespace `posix` <a id="namespace.posix">[[namespace.posix]]</a>
|
| 663 |
|
| 664 |
The behavior of a C++ program is undefined if it adds declarations or
|
| 665 |
definitions to namespace `posix` or to a namespace within namespace
|
| 666 |
`posix` unless otherwise specified. The namespace `posix` is reserved
|
| 667 |
for use by ISO/IEC 9945 and other POSIX standards.
|
| 668 |
|
| 669 |
##### Namespaces for future standardization <a id="namespace.future">[[namespace.future]]</a>
|
| 670 |
|
| 671 |
-
Top
|
| 672 |
-
|
| 673 |
-
The behavior of a C++program is undefined if it adds
|
| 674 |
-
definitions to such a namespace.
|
| 675 |
|
| 676 |
-
[*Example 1*: The top
|
| 677 |
future revisions of this International Standard. — *end example*]
|
| 678 |
|
| 679 |
#### Reserved names <a id="reserved.names">[[reserved.names]]</a>
|
| 680 |
|
| 681 |
The C++ standard library reserves the following kinds of names:
|
|
@@ -692,101 +700,133 @@ is undefined.
|
|
| 692 |
|
| 693 |
In namespace `std`, the following names are reserved for previous
|
| 694 |
standardization:
|
| 695 |
|
| 696 |
- `auto_ptr`,
|
|
|
|
| 697 |
- `binary_function`,
|
|
|
|
| 698 |
- `bind1st`,
|
| 699 |
- `bind2nd`,
|
| 700 |
- `binder1st`,
|
| 701 |
- `binder2nd`,
|
| 702 |
- `const_mem_fun1_ref_t`,
|
| 703 |
- `const_mem_fun1_t`,
|
| 704 |
- `const_mem_fun_ref_t`,
|
| 705 |
- `const_mem_fun_t`,
|
|
|
|
| 706 |
- `get_unexpected`,
|
|
|
|
|
|
|
|
|
|
| 707 |
- `mem_fun1_ref_t`,
|
| 708 |
- `mem_fun1_t`,
|
| 709 |
- `mem_fun_ref_t`,
|
| 710 |
- `mem_fun_ref`,
|
| 711 |
- `mem_fun_t`,
|
| 712 |
- `mem_fun`,
|
|
|
|
|
|
|
| 713 |
- `pointer_to_binary_function`,
|
| 714 |
- `pointer_to_unary_function`,
|
| 715 |
- `ptr_fun`,
|
| 716 |
- `random_shuffle`,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 717 |
- `set_unexpected`,
|
| 718 |
- `unary_function`,
|
|
|
|
|
|
|
| 719 |
- `unexpected`, and
|
| 720 |
- `unexpected_handler`.
|
| 721 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 722 |
##### Macro names <a id="macro.names">[[macro.names]]</a>
|
| 723 |
|
| 724 |
A translation unit that includes a standard library header shall not
|
| 725 |
`#define` or `#undef` names declared in any standard library header.
|
| 726 |
|
| 727 |
A translation unit shall not `#define` or `#undef` names lexically
|
| 728 |
-
identical to keywords, to the identifiers listed in
|
| 729 |
-
[[
|
| 730 |
-
[[dcl.attr]]
|
|
|
|
| 731 |
|
| 732 |
##### External linkage <a id="extern.names">[[extern.names]]</a>
|
| 733 |
|
| 734 |
Each name declared as an object with external linkage in a header is
|
| 735 |
reserved to the implementation to designate that library object with
|
| 736 |
-
external linkage, [^
|
| 737 |
namespace.
|
| 738 |
|
| 739 |
Each global function signature declared with external linkage in a
|
| 740 |
header is reserved to the implementation to designate that function
|
| 741 |
-
signature with external linkage.[^
|
| 742 |
|
| 743 |
Each name from the C standard library declared with external linkage is
|
| 744 |
reserved to the implementation for use as a name with `extern "C"`
|
| 745 |
linkage, both in namespace `std` and in the global namespace.
|
| 746 |
|
| 747 |
Each function signature from the C standard library declared with
|
| 748 |
external linkage is reserved to the implementation for use as a function
|
| 749 |
-
signature with both `extern "C"` and `extern "C++"` linkage,[^
|
| 750 |
a name of namespace scope in the global namespace.
|
| 751 |
|
| 752 |
##### Types <a id="extern.types">[[extern.types]]</a>
|
| 753 |
|
| 754 |
-
For each type T from the C standard library,
|
| 755 |
`std::T` are reserved to the implementation and, when defined, `::T`
|
| 756 |
shall be identical to `std::T`.
|
| 757 |
|
| 758 |
##### User-defined literal suffixes <a id="usrlit.suffix">[[usrlit.suffix]]</a>
|
| 759 |
|
| 760 |
-
Literal suffix identifiers
|
| 761 |
underscore are reserved for future standardization.
|
| 762 |
|
| 763 |
#### Headers <a id="alt.headers">[[alt.headers]]</a>
|
| 764 |
|
| 765 |
If a file with a name equivalent to the derived file name for one of the
|
| 766 |
C++ standard library headers is not provided as part of the
|
| 767 |
implementation, and a file with that name is placed in any of the
|
| 768 |
-
standard places for a source file to be included
|
| 769 |
behavior is undefined.
|
| 770 |
|
| 771 |
#### Derived classes <a id="derived.classes">[[derived.classes]]</a>
|
| 772 |
|
| 773 |
-
Virtual member function signatures defined for a base class in the
|
| 774 |
-
|
| 775 |
-
program
|
| 776 |
|
| 777 |
#### Replacement functions <a id="replacement.functions">[[replacement.functions]]</a>
|
| 778 |
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
program ([[definitions]]).
|
| 784 |
|
| 785 |
-
A C++program may provide the definition for any of the following
|
| 786 |
-
memory allocation function signatures declared in header
|
| 787 |
-
[[basic.stc.dynamic]], [[
|
| 788 |
|
| 789 |
``` cpp
|
| 790 |
operator new(std::size_t)
|
| 791 |
operator new(std::size_t, std::align_val_t)
|
| 792 |
operator new(std::size_t, const std::nothrow_t&)
|
|
@@ -817,19 +857,19 @@ operator delete[](void*, std::size_t, std::align_val_t)
|
|
| 817 |
operator delete[](void*, const std::nothrow_t&)
|
| 818 |
operator delete[](void*, std::align_val_t, const std::nothrow_t&)
|
| 819 |
```
|
| 820 |
|
| 821 |
The program’s definitions are used instead of the default versions
|
| 822 |
-
supplied by the implementation
|
| 823 |
-
|
| 824 |
-
|
| 825 |
-
|
| 826 |
|
| 827 |
#### Handler functions <a id="handler.functions">[[handler.functions]]</a>
|
| 828 |
|
| 829 |
The C++ standard library provides a default version of the following
|
| 830 |
-
handler function
|
| 831 |
|
| 832 |
- `terminate_handler`
|
| 833 |
|
| 834 |
A C++ program may install different handler functions during execution,
|
| 835 |
by supplying a pointer to a function defined in the program or the
|
|
@@ -855,34 +895,34 @@ function.
|
|
| 855 |
#### Other functions <a id="res.on.functions">[[res.on.functions]]</a>
|
| 856 |
|
| 857 |
In certain cases (replacement functions, handler functions, operations
|
| 858 |
on types used to instantiate standard library template components), the
|
| 859 |
C++ standard library depends on components supplied by a C++ program. If
|
| 860 |
-
these components do not meet their requirements, this
|
| 861 |
-
|
| 862 |
|
| 863 |
In particular, the effects are undefined in the following cases:
|
| 864 |
|
| 865 |
-
-
|
| 866 |
-
|
| 867 |
-
|
| 868 |
-
-
|
| 869 |
the installed handler function does not implement the semantics of the
|
| 870 |
-
applicable *Required behavior:* paragraph
|
| 871 |
-
-
|
| 872 |
component, if the operations on the type do not implement the
|
| 873 |
semantics of the applicable *Requirements* subclause (
|
| 874 |
[[allocator.requirements]], [[container.requirements]],
|
| 875 |
[[iterator.requirements]], [[algorithms.requirements]],
|
| 876 |
[[numeric.requirements]]). Operations on such types can report a
|
| 877 |
failure by throwing an exception unless otherwise specified.
|
| 878 |
-
-
|
| 879 |
operation exits via an exception, unless specifically allowed in the
|
| 880 |
applicable *Required behavior:* paragraph.
|
| 881 |
-
-
|
| 882 |
-
|
| 883 |
-
allowed for that component.
|
| 884 |
|
| 885 |
#### Function arguments <a id="res.on.arguments">[[res.on.arguments]]</a>
|
| 886 |
|
| 887 |
Each of the following applies to all arguments to functions defined in
|
| 888 |
the C++ standard library, unless explicitly stated otherwise.
|
|
@@ -897,74 +937,85 @@ the C++standard library, unless explicitly stated otherwise.
|
|
| 897 |
fact valid.
|
| 898 |
- If a function argument binds to an rvalue reference parameter, the
|
| 899 |
implementation may assume that this parameter is a unique reference to
|
| 900 |
this argument. \[*Note 1*: If the parameter is a generic parameter of
|
| 901 |
the form `T&&` and an lvalue of type `A` is bound, the argument binds
|
| 902 |
-
to an lvalue reference
|
| 903 |
-
|
| 904 |
-
|
| 905 |
-
|
| 906 |
-
|
| 907 |
-
|
| 908 |
-
|
| 909 |
-
|
| 910 |
|
| 911 |
#### Library object access <a id="res.on.objects">[[res.on.objects]]</a>
|
| 912 |
|
| 913 |
The behavior of a program is undefined if calls to standard library
|
| 914 |
functions from different threads may introduce a data race. The
|
| 915 |
conditions under which this may occur are specified in
|
| 916 |
[[res.on.data.races]].
|
| 917 |
|
| 918 |
[*Note 1*: Modifying an object of a standard library type that is
|
| 919 |
shared between threads risks undefined behavior unless objects of that
|
| 920 |
-
type are explicitly specified as being
|
| 921 |
the user supplies a locking mechanism. — *end note*]
|
| 922 |
|
| 923 |
If an object of a standard library type is accessed, and the beginning
|
| 924 |
-
of the object’s lifetime
|
| 925 |
access, or the access does not happen before the end of the object’s
|
| 926 |
lifetime, the behavior is undefined unless otherwise specified.
|
| 927 |
|
| 928 |
[*Note 2*: This applies even to objects such as mutexes intended for
|
| 929 |
thread synchronization. — *end note*]
|
| 930 |
|
| 931 |
-
####
|
| 932 |
|
| 933 |
-
Violation of
|
| 934 |
-
|
| 935 |
-
|
| 936 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 937 |
|
| 938 |
### Conforming implementations <a id="conforming">[[conforming]]</a>
|
| 939 |
|
| 940 |
#### Overview <a id="conforming.overview">[[conforming.overview]]</a>
|
| 941 |
|
| 942 |
-
|
| 943 |
-
implementations of the C++standard library.
|
| 944 |
|
| 945 |
An implementation’s use of headers is discussed in [[res.on.headers]],
|
| 946 |
its use of macros in [[res.on.macro.definitions]], non-member functions
|
| 947 |
in [[global.functions]], member functions in [[member.functions]],
|
| 948 |
data race avoidance in [[res.on.data.races]], access specifiers in
|
| 949 |
[[protection.within.classes]], class derivation in [[derivation]], and
|
| 950 |
exceptions in [[res.on.exception.handling]].
|
| 951 |
|
| 952 |
#### Headers <a id="res.on.headers">[[res.on.headers]]</a>
|
| 953 |
|
| 954 |
-
A C++header may include other C++headers. A C++header shall provide
|
| 955 |
-
declarations and definitions that appear in its synopsis. A C++
|
| 956 |
-
shown in its synopsis as including other C++headers shall
|
| 957 |
-
declarations and definitions that appear in the synopses of
|
| 958 |
-
headers.
|
| 959 |
|
| 960 |
Certain types and macros are defined in more than one header. Every such
|
| 961 |
entity shall be defined such that any header that defines it may be
|
| 962 |
-
included after any other header that also defines it
|
| 963 |
-
[[basic.def.odr]]).
|
| 964 |
|
| 965 |
-
The C standard library headers
|
| 966 |
their corresponding C++ standard library header, as described in
|
| 967 |
[[headers]].
|
| 968 |
|
| 969 |
#### Restrictions on macro definitions <a id="res.on.macro.definitions">[[res.on.macro.definitions]]</a>
|
| 970 |
|
|
@@ -977,31 +1028,30 @@ suitable for use in `#if` preprocessing directives, unless explicitly
|
|
| 977 |
stated otherwise.
|
| 978 |
|
| 979 |
#### Non-member functions <a id="global.functions">[[global.functions]]</a>
|
| 980 |
|
| 981 |
It is unspecified whether any non-member functions in the C++ standard
|
| 982 |
-
library are defined as
|
| 983 |
|
| 984 |
-
A call to a non-member function signature described in
|
| 985 |
-
|
| 986 |
-
|
| 987 |
-
function signatures.[^26]
|
| 988 |
|
| 989 |
An implementation shall not declare a non-member function signature with
|
| 990 |
additional default arguments.
|
| 991 |
|
| 992 |
Unless otherwise specified, calls made by functions in the standard
|
| 993 |
library to non-operator, non-member functions do not use functions from
|
| 994 |
-
another namespace which are found through
|
| 995 |
-
|
| 996 |
|
| 997 |
[*Note 1*:
|
| 998 |
|
| 999 |
The phrase “unless otherwise specified” applies to cases such as the
|
| 1000 |
-
swappable with requirements
|
| 1001 |
for overloaded operators allows argument-dependent lookup in cases like
|
| 1002 |
-
that of `ostream_iterator::operator=`
|
| 1003 |
|
| 1004 |
*Effects:*
|
| 1005 |
|
| 1006 |
``` cpp
|
| 1007 |
*out_stream << value;
|
|
@@ -1013,75 +1063,90 @@ return *this;
|
|
| 1013 |
— *end note*]
|
| 1014 |
|
| 1015 |
#### Member functions <a id="member.functions">[[member.functions]]</a>
|
| 1016 |
|
| 1017 |
It is unspecified whether any member functions in the C++ standard
|
| 1018 |
-
library are defined as
|
| 1019 |
|
| 1020 |
For a non-virtual member function described in the C++ standard library,
|
| 1021 |
an implementation may declare a different set of member function
|
| 1022 |
signatures, provided that any call to the member function that would
|
| 1023 |
select an overload from the set of declarations described in this
|
| 1024 |
-
|
| 1025 |
|
| 1026 |
[*Note 1*: For instance, an implementation may add parameters with
|
| 1027 |
default values, or replace a member function with default arguments with
|
| 1028 |
two or more member functions with equivalent behavior, or add additional
|
| 1029 |
signatures for a member function name. — *end note*]
|
| 1030 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1031 |
#### Constexpr functions and constructors <a id="constexpr.functions">[[constexpr.functions]]</a>
|
| 1032 |
|
| 1033 |
-
This
|
| 1034 |
-
|
| 1035 |
-
|
| 1036 |
-
|
| 1037 |
-
|
| 1038 |
-
|
| 1039 |
-
definitions.
|
| 1040 |
|
| 1041 |
#### Requirements for stable algorithms <a id="algorithm.stable">[[algorithm.stable]]</a>
|
| 1042 |
|
| 1043 |
When the requirements for an algorithm state that it is “stable” without
|
| 1044 |
further elaboration, it means:
|
| 1045 |
|
| 1046 |
-
- For the
|
| 1047 |
preserved.
|
| 1048 |
-
- For the
|
| 1049 |
-
|
| 1050 |
-
- For the
|
| 1051 |
-
|
| 1052 |
-
|
| 1053 |
-
|
| 1054 |
|
| 1055 |
#### Reentrancy <a id="reentrancy">[[reentrancy]]</a>
|
| 1056 |
|
| 1057 |
-
Except where explicitly specified in this
|
| 1058 |
*implementation-defined* which functions in the C++ standard library may
|
| 1059 |
be recursively reentered.
|
| 1060 |
|
| 1061 |
#### Data race avoidance <a id="res.on.data.races">[[res.on.data.races]]</a>
|
| 1062 |
|
| 1063 |
-
This
|
| 1064 |
-
prevent data races
|
| 1065 |
function shall meet each requirement unless otherwise specified.
|
| 1066 |
Implementations may prevent data races in cases other than those
|
| 1067 |
specified below.
|
| 1068 |
|
| 1069 |
A C++ standard library function shall not directly or indirectly access
|
| 1070 |
-
objects
|
| 1071 |
current thread unless the objects are accessed directly or indirectly
|
| 1072 |
via the function’s arguments, including `this`.
|
| 1073 |
|
| 1074 |
A C++ standard library function shall not directly or indirectly modify
|
| 1075 |
-
objects
|
| 1076 |
current thread unless the objects are accessed directly or indirectly
|
| 1077 |
via the function’s non-const arguments, including `this`.
|
| 1078 |
|
| 1079 |
-
[*Note 1*: This means, for example, that implementations can’t use
|
| 1080 |
-
static
|
| 1081 |
-
could cause a data race even in programs that
|
| 1082 |
-
objects between threads. — *end note*]
|
| 1083 |
|
| 1084 |
A C++ standard library function shall not access objects indirectly
|
| 1085 |
accessible via its arguments or via elements of its container arguments
|
| 1086 |
except by invoking functions required by its specification on those
|
| 1087 |
container elements.
|
|
@@ -1098,31 +1163,31 @@ Implementations may share their own internal objects between threads if
|
|
| 1098 |
the objects are not visible to users and are protected against data
|
| 1099 |
races.
|
| 1100 |
|
| 1101 |
Unless otherwise specified, C++ standard library functions shall perform
|
| 1102 |
all operations solely within the current thread if those operations have
|
| 1103 |
-
effects that are visible
|
| 1104 |
|
| 1105 |
[*Note 3*: This allows implementations to parallelize operations if
|
| 1106 |
there are no visible side effects. — *end note*]
|
| 1107 |
|
| 1108 |
#### Protection within classes <a id="protection.within.classes">[[protection.within.classes]]</a>
|
| 1109 |
|
| 1110 |
It is unspecified whether any function signature or class described in
|
| 1111 |
-
|
| 1112 |
-
|
| 1113 |
|
| 1114 |
#### Derived classes <a id="derivation">[[derivation]]</a>
|
| 1115 |
|
| 1116 |
-
An implementation may derive any class in the C++standard library from
|
| 1117 |
-
class with a name reserved to the implementation.
|
| 1118 |
|
| 1119 |
Certain classes defined in the C++ standard library are required to be
|
| 1120 |
-
derived from other classes in the C++standard library. An
|
| 1121 |
-
may derive such a class directly from the required base
|
| 1122 |
-
through a hierarchy of base classes with names reserved to
|
| 1123 |
-
implementation.
|
| 1124 |
|
| 1125 |
In any case:
|
| 1126 |
|
| 1127 |
- Every base class described as `virtual` shall be virtual;
|
| 1128 |
- Every base class not specified as `virtual` shall not be virtual;
|
|
@@ -1142,13 +1207,13 @@ type.
|
|
| 1142 |
|
| 1143 |
Functions from the C standard library shall not throw exceptions [^28]
|
| 1144 |
except when such a function calls a program-supplied function that
|
| 1145 |
throws an exception.[^29]
|
| 1146 |
|
| 1147 |
-
Destructor operations defined in the C++standard library shall not
|
| 1148 |
-
exceptions. Every destructor in the C++standard library shall
|
| 1149 |
-
if it had a non-throwing exception specification.
|
| 1150 |
|
| 1151 |
Functions defined in the C++ standard library that do not have a
|
| 1152 |
*Throws:* paragraph but do have a potentially-throwing exception
|
| 1153 |
specification may throw *implementation-defined* exceptions. [^30]
|
| 1154 |
Implementations should report errors by throwing exceptions of or
|
|
@@ -1160,157 +1225,189 @@ non-virtual function by adding a non-throwing exception specification.
|
|
| 1160 |
|
| 1161 |
#### Restrictions on storage of pointers <a id="res.on.pointer.storage">[[res.on.pointer.storage]]</a>
|
| 1162 |
|
| 1163 |
Objects constructed by the standard library that may hold a
|
| 1164 |
user-supplied pointer value or an integer of type `std::intptr_t` shall
|
| 1165 |
-
store such values in a traceable pointer location
|
| 1166 |
-
[[basic.stc.dynamic.safety]]
|
| 1167 |
|
| 1168 |
[*Note 1*: Other libraries are strongly encouraged to do the same,
|
| 1169 |
since not doing so may result in accidental use of pointers that are not
|
| 1170 |
safely derived. Libraries that store pointers outside the user’s address
|
| 1171 |
space should make it appear that they are stored and retrieved from a
|
| 1172 |
traceable pointer location. — *end note*]
|
| 1173 |
|
| 1174 |
#### Value of error codes <a id="value.error.codes">[[value.error.codes]]</a>
|
| 1175 |
|
| 1176 |
Certain functions in the C++ standard library report errors via a
|
| 1177 |
-
`std::error_code`
|
| 1178 |
`category()` member shall return `std::system_category()` for errors
|
| 1179 |
originating from the operating system, or a reference to an
|
| 1180 |
*implementation-defined* `error_category` object for errors originating
|
| 1181 |
elsewhere. The implementation shall define the possible values of
|
| 1182 |
`value()` for each of these error categories.
|
| 1183 |
|
| 1184 |
[*Example 1*: For operating systems that are based on POSIX,
|
| 1185 |
-
implementations
|
| 1186 |
-
|
| 1187 |
-
|
| 1188 |
-
|
| 1189 |
-
|
| 1190 |
-
|
| 1191 |
-
|
| 1192 |
|
| 1193 |
#### Moved-from state of library types <a id="lib.types.movedfrom">[[lib.types.movedfrom]]</a>
|
| 1194 |
|
| 1195 |
-
Objects of types defined in the C++standard library may be moved from
|
| 1196 |
-
[[class.copy]]
|
| 1197 |
implicitly generated. Unless otherwise specified, such moved-from
|
| 1198 |
objects shall be placed in a valid but unspecified state.
|
| 1199 |
|
| 1200 |
<!-- Link reference definitions -->
|
| 1201 |
[alg.c.library]: algorithms.md#alg.c.library
|
| 1202 |
[alg.sorting]: algorithms.md#alg.sorting
|
| 1203 |
[algorithm.stable]: #algorithm.stable
|
| 1204 |
[algorithms]: algorithms.md#algorithms
|
| 1205 |
[algorithms.requirements]: algorithms.md#algorithms.requirements
|
| 1206 |
-
[alloc.errors]:
|
|
|
|
| 1207 |
[allocator.requirements]: #allocator.requirements
|
| 1208 |
[allocator.requirements.completeness]: #allocator.requirements.completeness
|
| 1209 |
[allocator.traits]: utilities.md#allocator.traits
|
| 1210 |
[alt.headers]: #alt.headers
|
| 1211 |
[atomics]: atomics.md#atomics
|
| 1212 |
-
[
|
|
|
|
|
|
|
| 1213 |
[basic.def.odr]: basic.md#basic.def.odr
|
| 1214 |
[basic.fundamental]: basic.md#basic.fundamental
|
| 1215 |
[basic.life]: basic.md#basic.life
|
| 1216 |
[basic.link]: basic.md#basic.link
|
| 1217 |
[basic.lookup.argdep]: basic.md#basic.lookup.argdep
|
|
|
|
|
|
|
| 1218 |
[basic.scope.namespace]: basic.md#basic.scope.namespace
|
| 1219 |
[basic.start]: basic.md#basic.start
|
| 1220 |
[basic.stc.dynamic]: basic.md#basic.stc.dynamic
|
| 1221 |
[basic.stc.dynamic.safety]: basic.md#basic.stc.dynamic.safety
|
| 1222 |
[basic.types]: basic.md#basic.types
|
|
|
|
| 1223 |
[bitmask.types]: #bitmask.types
|
| 1224 |
[byte.strings]: #byte.strings
|
| 1225 |
-
[c.
|
| 1226 |
-
[c.strings]: strings.md#c.strings
|
| 1227 |
[character.seq]: #character.seq
|
| 1228 |
-
[class.
|
| 1229 |
-
[class.copy]:
|
| 1230 |
-
[class.
|
| 1231 |
-
[class.dtor]: special.md#class.dtor
|
| 1232 |
[class.mem]: class.md#class.mem
|
| 1233 |
[class.mfct]: class.md#class.mfct
|
| 1234 |
[class.this]: class.md#class.this
|
| 1235 |
[class.virtual]: class.md#class.virtual
|
|
|
|
| 1236 |
[compliance]: #compliance
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1237 |
[conforming]: #conforming
|
| 1238 |
[conforming.overview]: #conforming.overview
|
| 1239 |
[constexpr.functions]: #constexpr.functions
|
| 1240 |
[constraints]: #constraints
|
| 1241 |
[constraints.overview]: #constraints.overview
|
| 1242 |
[container.requirements]: containers.md#container.requirements
|
| 1243 |
[containers]: containers.md#containers
|
| 1244 |
[contents]: #contents
|
| 1245 |
-
[conv]:
|
|
|
|
| 1246 |
[conventions]: #conventions
|
| 1247 |
[cpp.include]: cpp.md#cpp.include
|
| 1248 |
-
[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1249 |
[dcl.array]: dcl.md#dcl.array
|
| 1250 |
[dcl.attr]: dcl.md#dcl.attr
|
| 1251 |
[dcl.constexpr]: dcl.md#dcl.constexpr
|
| 1252 |
[dcl.fct.default]: dcl.md#dcl.fct.default
|
| 1253 |
[dcl.init]: dcl.md#dcl.init
|
| 1254 |
[dcl.init.list]: dcl.md#dcl.init.list
|
| 1255 |
[dcl.inline]: dcl.md#dcl.inline
|
| 1256 |
[dcl.link]: dcl.md#dcl.link
|
|
|
|
| 1257 |
[definitions]: #definitions
|
| 1258 |
[depr]: future.md#depr
|
| 1259 |
[depr.c.headers]: future.md#depr.c.headers
|
| 1260 |
-
[depr.cstdalign.syn]: future.md#depr.cstdalign.syn
|
| 1261 |
-
[depr.cstdbool.syn]: future.md#depr.cstdbool.syn
|
| 1262 |
[derivation]: #derivation
|
| 1263 |
[derived.classes]: #derived.classes
|
| 1264 |
[description]: #description
|
| 1265 |
[diagnostics]: diagnostics.md#diagnostics
|
| 1266 |
[enumerated.types]: #enumerated.types
|
| 1267 |
[except]: except.md#except
|
|
|
|
|
|
|
| 1268 |
[expos.only.types]: #expos.only.types
|
| 1269 |
[expr.cond]: expr.md#expr.cond
|
| 1270 |
[expr.const]: expr.md#expr.const
|
| 1271 |
[expr.delete]: expr.md#expr.delete
|
| 1272 |
[expr.eq]: expr.md#expr.eq
|
| 1273 |
[expr.new]: expr.md#expr.new
|
| 1274 |
[expr.rel]: expr.md#expr.rel
|
|
|
|
|
|
|
| 1275 |
[extern.names]: #extern.names
|
| 1276 |
[extern.types]: #extern.types
|
| 1277 |
[function.objects]: utilities.md#function.objects
|
| 1278 |
[functions.within.classes]: #functions.within.classes
|
| 1279 |
[global.functions]: #global.functions
|
| 1280 |
[handler.functions]: #handler.functions
|
| 1281 |
[hash.requirements]: #hash.requirements
|
| 1282 |
[headers]: #headers
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1283 |
[input.output]: input.md#input.output
|
| 1284 |
[intro.compliance]: intro.md#intro.compliance
|
| 1285 |
[intro.defs]: intro.md#intro.defs
|
| 1286 |
-
[intro.
|
|
|
|
| 1287 |
[intro.refs]: intro.md#intro.refs
|
| 1288 |
[iterator.requirements]: iterators.md#iterator.requirements
|
| 1289 |
-
[iterator.requirements.general]: iterators.md#iterator.requirements.general
|
| 1290 |
[iterators]: iterators.md#iterators
|
| 1291 |
-
[
|
| 1292 |
-
[lex]:
|
| 1293 |
[lex.phases]: lex.md#lex.phases
|
|
|
|
| 1294 |
[lib.types.movedfrom]: #lib.types.movedfrom
|
| 1295 |
[library]: #library
|
| 1296 |
[library.c]: #library.c
|
|
|
|
| 1297 |
[library.general]: #library.general
|
| 1298 |
[locales]: localization.md#locales
|
| 1299 |
[localization]: localization.md#localization
|
| 1300 |
[macro.names]: #macro.names
|
| 1301 |
[member.functions]: #member.functions
|
| 1302 |
[meta]: utilities.md#meta
|
|
|
|
| 1303 |
[multibyte.strings]: #multibyte.strings
|
| 1304 |
[namespace.constraints]: #namespace.constraints
|
| 1305 |
[namespace.def]: dcl.md#namespace.def
|
| 1306 |
[namespace.future]: #namespace.future
|
| 1307 |
[namespace.posix]: #namespace.posix
|
| 1308 |
[namespace.std]: #namespace.std
|
| 1309 |
[namespace.udecl]: dcl.md#namespace.udecl
|
| 1310 |
-
[new.delete]:
|
| 1311 |
-
[new.handler]:
|
|
|
|
| 1312 |
[nullablepointer.requirements]: #nullablepointer.requirements
|
| 1313 |
[numeric.requirements]: numerics.md#numeric.requirements
|
| 1314 |
[numerics]: numerics.md#numerics
|
| 1315 |
[objects.within.classes]: #objects.within.classes
|
| 1316 |
[organization]: #organization
|
|
@@ -1318,71 +1415,73 @@ objects shall be placed in a valid but unspecified state.
|
|
| 1318 |
[over.literal]: over.md#over.literal
|
| 1319 |
[over.match]: over.md#over.match
|
| 1320 |
[over.oper]: over.md#over.oper
|
| 1321 |
[protection.within.classes]: #protection.within.classes
|
| 1322 |
[random.access.iterators]: iterators.md#random.access.iterators
|
|
|
|
| 1323 |
[re]: re.md#re
|
| 1324 |
[reentrancy]: #reentrancy
|
| 1325 |
[replacement.functions]: #replacement.functions
|
| 1326 |
[requirements]: #requirements
|
| 1327 |
[res.on.arguments]: #res.on.arguments
|
| 1328 |
[res.on.data.races]: #res.on.data.races
|
| 1329 |
[res.on.exception.handling]: #res.on.exception.handling
|
|
|
|
| 1330 |
[res.on.functions]: #res.on.functions
|
| 1331 |
[res.on.headers]: #res.on.headers
|
| 1332 |
[res.on.macro.definitions]: #res.on.macro.definitions
|
| 1333 |
[res.on.objects]: #res.on.objects
|
| 1334 |
[res.on.pointer.storage]: #res.on.pointer.storage
|
| 1335 |
-
[res.on.
|
| 1336 |
[reserved.names]: #reserved.names
|
|
|
|
| 1337 |
[std.exceptions]: diagnostics.md#std.exceptions
|
|
|
|
| 1338 |
[stream.types]: input.md#stream.types
|
| 1339 |
[strings]: strings.md#strings
|
| 1340 |
[structure]: #structure
|
| 1341 |
[structure.elements]: #structure.elements
|
| 1342 |
[structure.requirements]: #structure.requirements
|
| 1343 |
[structure.see.also]: #structure.see.also
|
| 1344 |
[structure.specifications]: #structure.specifications
|
| 1345 |
[structure.summary]: #structure.summary
|
| 1346 |
-
[support
|
| 1347 |
-
[support.
|
| 1348 |
-
[support.
|
| 1349 |
-
[support.
|
| 1350 |
-
[support.
|
| 1351 |
-
[support.
|
| 1352 |
-
[support.
|
| 1353 |
-
[support.
|
|
|
|
|
|
|
|
|
|
| 1354 |
[swappable.requirements]: #swappable.requirements
|
| 1355 |
[syserr]: diagnostics.md#syserr
|
| 1356 |
[syserr.errcode.overview]: diagnostics.md#syserr.errcode.overview
|
| 1357 |
-
[tab:
|
| 1358 |
-
[tab:
|
| 1359 |
-
[tab:
|
| 1360 |
-
[tab:
|
| 1361 |
-
[
|
| 1362 |
-
[
|
| 1363 |
-
[
|
| 1364 |
-
[
|
| 1365 |
-
[tab:hash]: #tab:hash
|
| 1366 |
-
[tab:identifiers.special]: lex.md#tab:identifiers.special
|
| 1367 |
-
[tab:library.categories]: #tab:library.categories
|
| 1368 |
-
[tab:moveassignable]: #tab:moveassignable
|
| 1369 |
-
[tab:nullablepointer]: #tab:nullablepointer
|
| 1370 |
-
[tab:utilities.allocator.requirements]: #tab:utilities.allocator.requirements
|
| 1371 |
[temp.deduct.call]: temp.md#temp.deduct.call
|
|
|
|
| 1372 |
[template.bitset]: utilities.md#template.bitset
|
| 1373 |
-
[terminate.handler]:
|
| 1374 |
[thread]: thread.md#thread
|
|
|
|
| 1375 |
[type.descriptions]: #type.descriptions
|
| 1376 |
[type.descriptions.general]: #type.descriptions.general
|
| 1377 |
[using]: #using
|
| 1378 |
[using.headers]: #using.headers
|
| 1379 |
[using.linkage]: #using.linkage
|
| 1380 |
[using.overview]: #using.overview
|
| 1381 |
[usrlit.suffix]: #usrlit.suffix
|
| 1382 |
[utilities]: utilities.md#utilities
|
| 1383 |
-
[utility]: utilities.md#utility
|
| 1384 |
[utility.arg.requirements]: #utility.arg.requirements
|
| 1385 |
[utility.requirements]: #utility.requirements
|
| 1386 |
[value.error.codes]: #value.error.codes
|
| 1387 |
[zombie.names]: #zombie.names
|
| 1388 |
|
|
@@ -1395,60 +1494,60 @@ objects shall be placed in a valid but unspecified state.
|
|
| 1395 |
|
| 1396 |
[^3]: To save space, items that do not apply to a class are omitted. For
|
| 1397 |
example, if a class does not specify any comparison functions, there
|
| 1398 |
will be no “Comparison functions” subclause.
|
| 1399 |
|
| 1400 |
-
[^4]: To save space,
|
| 1401 |
-
For example, if a function
|
| 1402 |
-
|
| 1403 |
|
| 1404 |
[^5]: This simplifies the presentation of complexity requirements in
|
| 1405 |
some cases.
|
| 1406 |
|
| 1407 |
[^6]: Examples from [[utility.requirements]] include:
|
| 1408 |
-
|
| 1409 |
-
Examples from [[iterator.requirements]]
|
| 1410 |
-
|
| 1411 |
|
| 1412 |
-
[^7]: Such as an integer type, with constant integer values
|
| 1413 |
-
[[basic.fundamental]]
|
| 1414 |
|
| 1415 |
-
[^8]: declared in `<clocale>`
|
| 1416 |
|
| 1417 |
[^9]: Many of the objects manipulated by function signatures declared in
|
| 1418 |
-
`<cstring>`
|
| 1419 |
-
|
| 1420 |
-
|
| 1421 |
|
| 1422 |
-
[^10]: A string
|
| 1423 |
|
| 1424 |
[^11]: An NTBS that contains characters only from the basic execution
|
| 1425 |
character set is also an NTMBS. Each multibyte character then
|
| 1426 |
consists of a single byte.
|
| 1427 |
|
| 1428 |
-
[^12]: The C standard library headers
|
| 1429 |
-
|
| 1430 |
-
library facilities
|
| 1431 |
global namespace.
|
| 1432 |
|
| 1433 |
[^13]: This gives implementers freedom to use inline namespaces to
|
| 1434 |
support multiple configurations of the library.
|
| 1435 |
|
| 1436 |
[^14]: A header is not necessarily a source file, nor are the sequences
|
| 1437 |
delimited by `<` and `>` in header names necessarily valid source
|
| 1438 |
-
file names
|
| 1439 |
|
| 1440 |
[^15]: It is intentional that there is no C++ header for any of these C
|
| 1441 |
headers: `<stdatomic.h>`, `<stdnoreturn.h>`, `<threads.h>`.
|
| 1442 |
|
| 1443 |
[^16]: This disallows the practice, allowed in C, of providing a masking
|
| 1444 |
macro in addition to the function prototype. The only way to achieve
|
| 1445 |
equivalent inline behavior in C++ is to provide a definition as an
|
| 1446 |
extern inline function.
|
| 1447 |
|
| 1448 |
-
[^17]: In particular, including the standard header `<iso646.h>`
|
| 1449 |
-
|
| 1450 |
|
| 1451 |
[^18]: The `".h"` headers dump all their names into the global
|
| 1452 |
namespace, whereas the newer forms keep their names in namespace
|
| 1453 |
`std`. Therefore, the newer forms are the preferred forms for all
|
| 1454 |
uses except for C++ programs which are intended to be strictly
|
|
@@ -1460,43 +1559,50 @@ objects shall be placed in a valid but unspecified state.
|
|
| 1460 |
from the C standard library is by including the header that declares
|
| 1461 |
it, notwithstanding the latitude granted in 7.1.4 of the C Standard.
|
| 1462 |
|
| 1463 |
[^21]: Any library code that instantiates other library templates must
|
| 1464 |
be prepared to work adequately with any user-supplied specialization
|
| 1465 |
-
that meets the minimum requirements of this
|
| 1466 |
|
| 1467 |
-
[^22]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1468 |
defined in `<cerrno>`.
|
| 1469 |
|
| 1470 |
-
[^
|
| 1471 |
linkage includes `setjmp(jmp_buf)`, declared or defined in
|
| 1472 |
`<csetjmp>`, and `va_end(va_list)`, declared or defined in
|
| 1473 |
`<cstdarg>`.
|
| 1474 |
|
| 1475 |
-
[^
|
| 1476 |
`<cwctype>` are always reserved, notwithstanding the restrictions
|
| 1477 |
imposed in subclause 4.5.1 of Amendment 1 to the C Standard for
|
| 1478 |
these headers.
|
| 1479 |
|
| 1480 |
-
[^25]: These types are `clock_t`, `div_t`, `FILE`, `fpos_t`, `lconv`,
|
| 1481 |
-
`ldiv_t`, `mbstate_t`, `ptrdiff_t`, `sig_atomic_t`, `size_t`,
|
| 1482 |
-
`time_t`, `tm`, `va_list`, `wctrans_t`, `wctype_t`, and `wint_t`.
|
| 1483 |
-
|
| 1484 |
[^26]: A valid C++ program always calls the expected library non-member
|
| 1485 |
function. An implementation may also define additional non-member
|
| 1486 |
functions that would otherwise not be called by a valid C++ program.
|
| 1487 |
|
| 1488 |
[^27]: There is an implicit exception to this rule for types that are
|
| 1489 |
-
described as synonyms for basic integral types, such as `size_t`
|
| 1490 |
-
[[support.types]]
|
| 1491 |
|
| 1492 |
[^28]: That is, the C library functions can all be treated as if they
|
| 1493 |
are marked `noexcept`. This allows implementations to make
|
| 1494 |
performance optimizations based on the absence of exceptions at
|
| 1495 |
runtime.
|
| 1496 |
|
| 1497 |
-
[^29]: The functions `qsort()` and `bsearch()`
|
| 1498 |
this condition.
|
| 1499 |
|
| 1500 |
[^30]: In particular, they can report a failure to allocate storage by
|
| 1501 |
throwing an exception of type `bad_alloc`, or a class derived from
|
| 1502 |
-
`bad_alloc`
|
|
|
|
| 1 |
## Library-wide requirements <a id="requirements">[[requirements]]</a>
|
| 2 |
|
| 3 |
+
This subclause specifies requirements that apply to the entire C++
|
| 4 |
+
standard library. [[support]] through [[thread]] and [[depr]] specify
|
| 5 |
+
the requirements of individual entities within the library.
|
|
|
|
| 6 |
|
| 7 |
Requirements specified in terms of interactions between threads do not
|
| 8 |
apply to programs having only a single thread of execution.
|
| 9 |
|
| 10 |
Within this subclause, [[organization]] describes the library’s contents
|
|
|
|
| 14 |
[[constraints]] describes constraints on well-formed C++ programs, and
|
| 15 |
[[conforming]] describes constraints on conforming implementations.
|
| 16 |
|
| 17 |
### Library contents and organization <a id="organization">[[organization]]</a>
|
| 18 |
|
| 19 |
+
[[contents]] describes the entities and macros defined in the C++
|
| 20 |
+
standard library. [[headers]] lists the standard library headers and
|
| 21 |
some constraints on those headers. [[compliance]] lists requirements for
|
| 22 |
a freestanding implementation of the C++ standard library.
|
| 23 |
|
| 24 |
#### Library contents <a id="contents">[[contents]]</a>
|
| 25 |
|
| 26 |
+
The C++ standard library provides definitions for the entities and
|
| 27 |
+
macros described in the synopses of the C++ standard library headers
|
| 28 |
+
[[headers]], unless otherwise specified.
|
| 29 |
|
| 30 |
All library entities except `operator new` and `operator delete` are
|
| 31 |
defined within the namespace `std` or namespaces nested within namespace
|
| 32 |
`std`.[^12] It is unspecified whether names declared in a specific
|
| 33 |
namespace are declared directly in that namespace or in an inline
|
| 34 |
namespace inside that namespace.[^13]
|
| 35 |
|
| 36 |
Whenever a name `x` defined in the standard library is mentioned, the
|
| 37 |
name `x` is assumed to be fully qualified as `::std::x`, unless
|
| 38 |
+
explicitly described otherwise. For example, if the *Effects:* element
|
| 39 |
for library function `F` is described as calling library function `G`,
|
| 40 |
the function `::std::G` is meant.
|
| 41 |
|
| 42 |
#### Headers <a id="headers">[[headers]]</a>
|
| 43 |
|
| 44 |
Each element of the C++ standard library is declared or defined (as
|
| 45 |
appropriate) in a *header*.[^14]
|
| 46 |
|
| 47 |
The C++ standard library provides the *C++ library headers*, shown in
|
| 48 |
+
[[headers.cpp]].
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
The facilities of the C standard library are provided in the additional
|
| 51 |
+
headers shown in [[headers.cpp.c]]. [^15]
|
| 52 |
|
| 53 |
+
The headers listed in [[headers.cpp]], or, for a freestanding
|
| 54 |
+
implementation, the subset of such headers that are provided by the
|
| 55 |
+
implementation, are collectively known as the
|
| 56 |
+
*importable C++ library headers*.
|
| 57 |
|
| 58 |
+
[*Note 1*: Importable C++ library headers can be imported as module
|
| 59 |
+
units [[module.import]]. — *end note*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
+
[*Example 1*:
|
| 62 |
|
| 63 |
+
``` cpp
|
| 64 |
+
import <vector>; // imports the <vector> header unit
|
| 65 |
+
std::vector<int> vi; // OK
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
— *end example*]
|
| 69 |
+
|
| 70 |
+
Except as noted in [[library]] through [[thread]] and [[depr]], the
|
| 71 |
+
contents of each header `cname` is the same as that of the corresponding
|
| 72 |
+
header `name.h` as specified in the C standard library [[intro.refs]].
|
| 73 |
+
In the C++ standard library, however, the declarations (except for names
|
| 74 |
+
which are defined as macros in C) are within namespace scope
|
| 75 |
+
[[basic.scope.namespace]] of the namespace `std`. It is unspecified
|
| 76 |
+
whether these names (including any overloads added in [[support]]
|
| 77 |
+
through [[thread]] and [[depr]]) are first declared within the global
|
| 78 |
+
namespace scope and are then injected into namespace `std` by explicit
|
| 79 |
+
*using-declaration*s [[namespace.udecl]].
|
| 80 |
|
| 81 |
Names which are defined as macros in C shall be defined as macros in the
|
| 82 |
C++ standard library, even if C grants license for implementation as
|
| 83 |
functions.
|
| 84 |
|
| 85 |
+
[*Note 2*: The names defined as macros in C include the following:
|
| 86 |
`assert`, `offsetof`, `setjmp`, `va_arg`, `va_end`, and
|
| 87 |
`va_start`. — *end note*]
|
| 88 |
|
| 89 |
Names that are defined as functions in C shall be defined as functions
|
| 90 |
in the C++ standard library.[^16]
|
| 91 |
|
| 92 |
+
Identifiers that are keywords or operators in C++ shall not be defined
|
| 93 |
+
as macros in C++ standard library headers.[^17]
|
| 94 |
|
| 95 |
[[depr.c.headers]], C standard library headers, describes the effects of
|
| 96 |
using the `name.h` (C header) form in a C++ program.[^18]
|
| 97 |
|
| 98 |
Annex K of the C standard describes a large number of functions, with
|
|
|
|
| 103 |
generally take an additional argument whose value is the size of the
|
| 104 |
result array. If any C++ header is included, it is
|
| 105 |
*implementation-defined* whether any of these names is declared in the
|
| 106 |
global namespace. (None of them is declared in namespace `std`.)
|
| 107 |
|
| 108 |
+
[[c.annex.k.names]] lists the Annex K names that may be declared in some
|
| 109 |
+
header. These names are also subject to the restrictions of
|
| 110 |
+
[[macro.names]].
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
#### Freestanding implementations <a id="compliance">[[compliance]]</a>
|
| 113 |
|
| 114 |
+
Two kinds of implementations are defined: *hosted* and *freestanding*
|
| 115 |
+
[[intro.compliance]]; the kind of the implementation is
|
| 116 |
+
*implementation-defined*. For a hosted implementation, this document
|
| 117 |
+
describes the set of available headers.
|
| 118 |
|
| 119 |
A freestanding implementation has an *implementation-defined* set of
|
| 120 |
+
headers. This set shall include at least the headers shown in
|
| 121 |
+
[[headers.cpp.fs]].
|
| 122 |
|
| 123 |
+
**Table: C++ headers for freestanding implementations** <a id="headers.cpp.fs">[headers.cpp.fs]</a>
|
| 124 |
|
| 125 |
| Subclause | | Header |
|
| 126 |
+
| ---------------------- | ------------------------- | ------------------------------------------------ |
|
|
|
|
| 127 |
| [[support.types]] | Types | `<cstddef>` |
|
| 128 |
+
| [[support.limits]] | Implementation properties | `<cfloat>`, `<climits>`, `<limits>`, `<version>` |
|
| 129 |
| [[cstdint]] | Integer types | `<cstdint>` |
|
| 130 |
| [[support.start.term]] | Start and termination | `<cstdlib>` |
|
| 131 |
| [[support.dynamic]] | Dynamic memory management | `<new>` |
|
| 132 |
| [[support.rtti]] | Type identification | `<typeinfo>` |
|
| 133 |
+
| [[support.srcloc]] | Source location | `<source_location>` |
|
| 134 |
| [[support.exception]] | Exception handling | `<exception>` |
|
| 135 |
| [[support.initlist]] | Initializer lists | `<initializer_list>` |
|
| 136 |
+
| [[cmp]] | Comparisons | `<compare>` |
|
| 137 |
+
| [[support.coroutine]] | Coroutines support | `<coroutine>` |
|
| 138 |
| [[support.runtime]] | Other runtime support | `<cstdarg>` |
|
| 139 |
+
| [[concepts]] | Concepts library | `<concepts>` |
|
| 140 |
| [[meta]] | Type traits | `<type_traits>` |
|
| 141 |
+
| [[bit]] | Bit manipulation | `<bit>` |
|
| 142 |
| [[atomics]] | Atomics | `<atomic>` |
|
|
|
|
| 143 |
|
| 144 |
|
| 145 |
The supplied version of the header `<cstdlib>` shall declare at least
|
| 146 |
the functions `abort`, `atexit`, `at_quick_exit`, `exit`, and
|
| 147 |
+
`quick_exit` [[support.start.term]]. The supplied version of the header
|
| 148 |
+
`<atomic>` shall meet the same requirements as for a hosted
|
| 149 |
+
implementation except that support for always lock-free integral atomic
|
| 150 |
+
types [[atomics.lockfree]] is *implementation-defined*, and whether or
|
| 151 |
+
not the type aliases `atomic_signed_lock_free` and
|
| 152 |
+
`atomic_unsigned_lock_free` are defined [[atomics.alias]] is
|
| 153 |
+
*implementation-defined*. The other headers listed in this table shall
|
| 154 |
+
meet the same requirements as for a hosted implementation.
|
| 155 |
|
| 156 |
### Using the library <a id="using">[[using]]</a>
|
| 157 |
|
| 158 |
#### Overview <a id="using.overview">[[using.overview]]</a>
|
| 159 |
|
| 160 |
+
Subclause [[using]] describes how a C++ program gains access to the
|
| 161 |
+
facilities of the C++ standard library. [[using.headers]] describes
|
| 162 |
+
effects during translation phase 4, while [[using.linkage]] describes
|
| 163 |
+
effects during phase 8 [[lex.phases]].
|
| 164 |
|
| 165 |
#### Headers <a id="using.headers">[[using.headers]]</a>
|
| 166 |
|
| 167 |
The entities in the C++ standard library are defined in headers, whose
|
| 168 |
contents are made available to a translation unit when it contains the
|
| 169 |
+
appropriate `#include` preprocessing directive [[cpp.include]] or the
|
| 170 |
+
appropriate `import` declaration [[module.import]].
|
| 171 |
|
| 172 |
+
A translation unit may include library headers in any order
|
| 173 |
+
[[lex.separate]]. Each may be included more than once, with no effect
|
| 174 |
+
different from being included exactly once, except that the effect of
|
| 175 |
+
including either `<cassert>` or `<assert.h>` depends each time on the
|
| 176 |
+
lexically current definition of `NDEBUG`.[^19]
|
| 177 |
|
| 178 |
A translation unit shall include a header only outside of any
|
| 179 |
+
declaration or definition and, in the case of a module unit, only in its
|
| 180 |
+
*global-module-fragment*, and shall include the header or import the
|
| 181 |
+
corresponding header unit lexically before the first reference in that
|
| 182 |
+
translation unit to any of the entities declared in that header. No
|
| 183 |
+
diagnostic is required.
|
| 184 |
|
| 185 |
#### Linkage <a id="using.linkage">[[using.linkage]]</a>
|
| 186 |
|
| 187 |
+
Entities in the C++ standard library have external linkage
|
| 188 |
+
[[basic.link]]. Unless otherwise specified, objects and functions have
|
| 189 |
+
the default `extern "C++"` linkage [[dcl.link]].
|
| 190 |
|
| 191 |
Whether a name from the C standard library declared with external
|
| 192 |
linkage has `extern "C"` or `extern "C++"` linkage is
|
| 193 |
*implementation-defined*. It is recommended that an implementation use
|
| 194 |
`extern "C++"` linkage for this purpose.[^20]
|
| 195 |
|
| 196 |
+
Objects and functions defined in the library and required by a C++
|
| 197 |
+
program are included in the program prior to program startup.
|
| 198 |
|
| 199 |
+
See also replacement functions [[replacement.functions]], runtime
|
| 200 |
+
changes [[handler.functions]].
|
| 201 |
|
| 202 |
### Requirements on types and expressions <a id="utility.requirements">[[utility.requirements]]</a>
|
| 203 |
|
| 204 |
[[utility.arg.requirements]] describes requirements on types and
|
| 205 |
expressions used to instantiate templates defined in the C++ standard
|
|
|
|
| 213 |
|
| 214 |
#### Template argument requirements <a id="utility.arg.requirements">[[utility.arg.requirements]]</a>
|
| 215 |
|
| 216 |
The template definitions in the C++ standard library refer to various
|
| 217 |
named requirements whose details are set out in Tables
|
| 218 |
+
[[tab:cpp17.equalitycomparable]]– [[tab:cpp17.destructible]]. In these
|
| 219 |
+
tables, `T` is an object or reference type to be supplied by a C++
|
| 220 |
+
program instantiating a template; `a`, `b`, and `c` are values of type
|
| 221 |
+
(possibly `const`) `T`; `s` and `t` are modifiable lvalues of type `T`;
|
| 222 |
+
`u` denotes an identifier; `rv` is an rvalue of type `T`; and `v` is an
|
| 223 |
lvalue of type (possibly `const`) `T` or an rvalue of type `const T`.
|
| 224 |
|
| 225 |
In general, a default constructor is not required. Certain container
|
| 226 |
class member function signatures specify `T()` as a default argument.
|
| 227 |
+
`T()` shall be a well-defined expression [[dcl.init]] if one of those
|
| 228 |
+
signatures is called using the default argument [[dcl.fct.default]].
|
| 229 |
|
| 230 |
+
**Table: Cpp17EqualityComparable requirements** <a id="cpp17.equalitycomparable">[cpp17.equalitycomparable]</a>
|
| 231 |
|
| 232 |
| Expression | Return type |
|
| 233 |
| ---------- | ----------- |
|
| 234 |
| `a == b` | convertible to `bool` | `==` is an equivalence relation, that is, it has the following properties: For all `a`, `a == a`.; If `a == b`, then `b == a`.; If `a == b` and `b == c`, then `a == c`. |
|
| 235 |
|
| 236 |
+
|
| 237 |
+
**Table: Cpp17LessThanComparable requirements** <a id="cpp17.lessthancomparable">[cpp17.lessthancomparable]</a>
|
| 238 |
|
| 239 |
| Expression | Return type | Requirement |
|
| 240 |
+
| ---------- | --------------------- | ------------------------------------------------------ |
|
| 241 |
+
| `a < b` | convertible to `bool` | `<` is a strict weak ordering relation [[alg.sorting]] |
|
| 242 |
|
| 243 |
+
|
| 244 |
+
**Table: Cpp17DefaultConstructible requirements** <a id="cpp17.defaultconstructible">[cpp17.defaultconstructible]</a>
|
| 245 |
|
| 246 |
| Expression | Post-condition |
|
| 247 |
| -------------- | ------------------------------------------------------------------- |
|
| 248 |
| `T t;` | object `t` is default-initialized |
|
| 249 |
| `T u{};` | object `u` is value-initialized or aggregate-initialized |
|
| 250 |
| `T()`<br>`T{}` | an object of type `T` is value-initialized or aggregate-initialized |
|
| 251 |
|
| 252 |
+
|
| 253 |
[*Note 1*: `rv` must still meet the requirements of the library
|
| 254 |
component that is using it. The operations listed in those requirements
|
| 255 |
must work as specified whether `rv` has been moved from or
|
| 256 |
not. — *end note*]
|
| 257 |
|
| 258 |
+
**Table: Cpp17CopyConstructible requirements (in addition to Cpp17MoveConstructible)** <a id="cpp17.copyconstructible">[cpp17.copyconstructible]</a>
|
| 259 |
|
| 260 |
| Expression | Post-condition |
|
| 261 |
| ---------- | --------------------------------------------------------- |
|
| 262 |
| `T u = v;` | the value of `v` is unchanged and is equivalent to ` u` |
|
| 263 |
| `T(v)` | the value of `v` is unchanged and is equivalent to `T(v)` |
|
| 264 |
|
| 265 |
+
|
| 266 |
[*Note 2*: `rv` must still meet the requirements of the library
|
| 267 |
component that is using it, whether or not `t` and `rv` refer to the
|
| 268 |
same object. The operations listed in those requirements must work as
|
| 269 |
specified whether `rv` has been moved from or not. — *end note*]
|
| 270 |
|
| 271 |
+
**Table: Cpp17CopyAssignable requirements (in addition to Cpp17MoveAssignable)** <a id="cpp17.copyassignable">[cpp17.copyassignable]</a>
|
| 272 |
|
| 273 |
| Expression | Return type | Return value | Post-condition |
|
| 274 |
| ---------- | ----------- | ------------ | ------------------------------------------------------- |
|
| 275 |
| `t = v` | `T&` | `t` | `t` is equivalent to `v`, the value of `v` is unchanged |
|
| 276 |
|
| 277 |
|
| 278 |
+
[*Note 3*: Array types and non-object types are not
|
| 279 |
+
*Cpp17Destructible*. — *end note*]
|
| 280 |
|
| 281 |
+
#### Swappable requirements <a id="swappable.requirements">[[swappable.requirements]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
|
| 283 |
This subclause provides definitions for swappable types and expressions.
|
| 284 |
In these definitions, let `t` denote an expression of type `T`, and let
|
| 285 |
`u` denote an expression of type `U`.
|
| 286 |
|
|
|
|
| 293 |
and
|
| 294 |
- the object referred to by `u` has the value originally held by `t`.
|
| 295 |
|
| 296 |
The context in which `swap(t, u)` and `swap(u, t)` are evaluated shall
|
| 297 |
ensure that a binary non-member function named “swap” is selected via
|
| 298 |
+
overload resolution [[over.match]] on a candidate set that includes:
|
| 299 |
|
| 300 |
+
- the two `swap` function templates defined in `<utility>` and
|
| 301 |
+
- the lookup set produced by argument-dependent lookup
|
| 302 |
+
[[basic.lookup.argdep]].
|
|
|
|
| 303 |
|
| 304 |
[*Note 1*: If `T` and `U` are both fundamental types or arrays of
|
| 305 |
fundamental types and the declarations from the header `<utility>` are
|
| 306 |
in scope, the overall lookup set described above is equivalent to that
|
| 307 |
of the qualified name lookup applied to the expression `std::swap(t, u)`
|
|
|
|
| 312 |
appropriate evaluation context. — *end note*]
|
| 313 |
|
| 314 |
An rvalue or lvalue `t` is *swappable* if and only if `t` is swappable
|
| 315 |
with any rvalue or lvalue, respectively, of type `T`.
|
| 316 |
|
| 317 |
+
A type `X` meeting any of the iterator requirements
|
| 318 |
+
[[iterator.requirements]] meets the *Cpp17ValueSwappable* requirements
|
| 319 |
+
if, for any dereferenceable object `x` of type `X`, `*x` is swappable.
|
|
|
|
| 320 |
|
| 321 |
[*Example 1*:
|
| 322 |
|
| 323 |
User code can ensure that the evaluation of `swap` calls is performed in
|
| 324 |
an appropriate context under the various conditions as follows:
|
|
|
|
| 336 |
|
| 337 |
// Requires: lvalues of T shall be swappable.
|
| 338 |
template<class T>
|
| 339 |
void lv_swap(T& t1, T& t2) {
|
| 340 |
using std::swap;
|
| 341 |
+
swap(t1, t2); // OK: uses swappable conditions for lvalues of type T
|
| 342 |
+
}
|
| 343 |
|
| 344 |
namespace N {
|
| 345 |
struct A { int m; };
|
| 346 |
struct Proxy { A* a; };
|
| 347 |
Proxy proxy(A& a) { return Proxy{ &a }; }
|
|
|
|
| 364 |
}
|
| 365 |
```
|
| 366 |
|
| 367 |
— *end example*]
|
| 368 |
|
| 369 |
+
#### *Cpp17NullablePointer* requirements <a id="nullablepointer.requirements">[[nullablepointer.requirements]]</a>
|
| 370 |
|
| 371 |
+
A *Cpp17NullablePointer* type is a pointer-like type that supports null
|
| 372 |
+
values. A type `P` meets the *Cpp17NullablePointer* requirements if:
|
| 373 |
|
| 374 |
+
- `P` meets the *Cpp17EqualityComparable*, *Cpp17DefaultConstructible*,
|
| 375 |
+
*Cpp17CopyConstructible*, *Cpp17CopyAssignable*, and
|
| 376 |
+
*Cpp17Destructible* requirements,
|
| 377 |
+
- lvalues of type `P` are swappable [[swappable.requirements]],
|
| 378 |
+
- the expressions shown in [[cpp17.nullablepointer]] are valid and have
|
| 379 |
+
the indicated semantics, and
|
| 380 |
+
- `P` meets all the other requirements of this subclause.
|
| 381 |
|
| 382 |
A value-initialized object of type `P` produces the null value of the
|
| 383 |
type. The null value shall be equivalent only to itself. A
|
| 384 |
default-initialized object of type `P` may have an indeterminate value.
|
| 385 |
|
| 386 |
[*Note 1*: Operations involving indeterminate values may cause
|
| 387 |
undefined behavior. — *end note*]
|
| 388 |
|
| 389 |
An object `p` of type `P` can be contextually converted to `bool`
|
| 390 |
+
[[conv]]. The effect shall be as if `p != nullptr` had been evaluated in
|
| 391 |
+
place of `p`.
|
| 392 |
|
| 393 |
+
No operation which is part of the *Cpp17NullablePointer* requirements
|
| 394 |
+
shall exit via an exception.
|
| 395 |
|
| 396 |
+
In [[cpp17.nullablepointer]], `u` denotes an identifier, `t` denotes a
|
| 397 |
+
non-`const` lvalue of type `P`, `a` and `b` denote values of type
|
| 398 |
+
(possibly `const`) `P`, and `np` denotes a value of type (possibly
|
| 399 |
`const`) `std::nullptr_t`.
|
| 400 |
|
| 401 |
+
**Table: Cpp17NullablePointer requirements** <a id="cpp17.nullablepointer">[cpp17.nullablepointer]</a>
|
| 402 |
|
| 403 |
+
| Expression | Return type | Operational semantics |
|
| 404 |
+
| -------------- | ---------------------------------- | --------------------------- |
|
| 405 |
+
| `P u(np);`<br> | | Ensures: `u == nullptr` |
|
| 406 |
| `P u = np;` | | |
|
| 407 |
+
| `P(np)` | | Ensures: `P(np) == nullptr` |
|
| 408 |
+
| `t = np` | `P&` | Ensures: `t == nullptr` |
|
| 409 |
| `a != b` | contextually convertible to `bool` | `!(a == b)` |
|
| 410 |
| `a == np` | contextually convertible to `bool` | `a == P()` |
|
| 411 |
| `np == a` | | |
|
| 412 |
| `a != np` | contextually convertible to `bool` | `!(a == np)` |
|
| 413 |
| `np != a` | | |
|
| 414 |
|
| 415 |
|
| 416 |
+
#### *Cpp17Hash* requirements <a id="hash.requirements">[[hash.requirements]]</a>
|
| 417 |
|
| 418 |
+
A type `H` meets the requirements if:
|
| 419 |
|
| 420 |
+
- it is a function object type [[function.objects]],
|
| 421 |
+
- it meets the *Cpp17CopyConstructible* ([[cpp17.copyconstructible]])
|
| 422 |
+
and *Cpp17Destructible* ([[cpp17.destructible]]) requirements, and
|
| 423 |
+
- the expressions shown in [[cpp17.hash]] are valid and have the
|
| 424 |
indicated semantics.
|
| 425 |
|
| 426 |
Given `Key` is an argument type for function objects of type `H`, in
|
| 427 |
+
[[cpp17.hash]] `h` is a value of type (possibly `const`) `H`, `u` is an
|
| 428 |
+
lvalue of type `Key`, and `k` is a value of a type convertible to
|
| 429 |
(possibly `const`) `Key`.
|
| 430 |
|
| 431 |
[*Note 1*: Thus all evaluations of the expression `h(k)` with the same
|
| 432 |
value for `k` yield the same result for a given execution of the
|
| 433 |
program. — *end note*]
|
| 434 |
|
| 435 |
+
#### *Cpp17Allocator* requirements <a id="allocator.requirements">[[allocator.requirements]]</a>
|
| 436 |
|
| 437 |
The library describes a standard set of requirements for *allocators*,
|
| 438 |
which are class-type objects that encapsulate the information about an
|
| 439 |
allocation model. This information includes the knowledge of pointer
|
| 440 |
types, the type of their difference, the type of the size of objects in
|
| 441 |
this allocation model, as well as the memory allocation and deallocation
|
| 442 |
+
primitives for it. All of the string types [[strings]], containers
|
| 443 |
+
[[containers]] (except `array`), string buffers and string streams
|
| 444 |
+
[[input.output]], and `match_results` [[re]] are parameterized in terms
|
| 445 |
+
of allocators.
|
| 446 |
|
| 447 |
+
The class template `allocator_traits` [[allocator.traits]] supplies a
|
| 448 |
+
uniform interface to all allocator types. [[allocator.req.var]]
|
| 449 |
+
describes the types manipulated through allocators. [[cpp17.allocator]]
|
| 450 |
+
describes the requirements on allocator types and thus on types used to
|
| 451 |
+
instantiate `allocator_traits`. A requirement is optional if the last
|
| 452 |
+
column of [[cpp17.allocator]] specifies a default for a given
|
| 453 |
+
expression. Within the standard library `allocator_traits` template, an
|
| 454 |
+
optional requirement that is not supplied by an allocator is replaced by
|
| 455 |
+
the specified default expression. A user specialization of
|
| 456 |
+
`allocator_traits` may provide different defaults and may provide
|
|
|
|
| 457 |
defaults for different requirements than the primary template. Within
|
| 458 |
+
Tables [[tab:allocator.req.var]] and [[tab:cpp17.allocator]], the use
|
| 459 |
+
of `move` and `forward` always refers to `std::move` and `std::forward`,
|
| 460 |
+
respectively.
|
| 461 |
|
| 462 |
[*Note 1*: If `n == 0`, the return value is unspecified. — *end note*]
|
| 463 |
|
| 464 |
Note A: The member class template `rebind` in the table above is
|
| 465 |
effectively a typedef template.
|
|
|
|
| 475 |
`allocator_traits` template uses `SomeAllocator<U, Args>` in place of
|
| 476 |
`Allocator::{}rebind<U>::other` by default. For allocator types that are
|
| 477 |
not template instantiations of the above form, no default is provided.
|
| 478 |
|
| 479 |
Note B: If `X::propagate_on_container_copy_assignment::value` is `true`,
|
| 480 |
+
`X` shall meet the *Cpp17CopyAssignable* requirements (
|
| 481 |
+
[[cpp17.copyassignable]]) and the copy operation shall not throw
|
| 482 |
exceptions. If `X::propagate_on_container_move_assignment::value` is
|
| 483 |
+
`true`, `X` shall meet the *Cpp17MoveAssignable* requirements (
|
| 484 |
+
[[cpp17.moveassignable]]) and the move operation shall not throw
|
| 485 |
exceptions. If `X::propagate_on_container_swap::value` is `true`,
|
| 486 |
+
lvalues of type `X` shall be swappable [[swappable.requirements]] and
|
| 487 |
the `swap` operation shall not throw exceptions.
|
| 488 |
|
| 489 |
+
An allocator type `X` shall meet the *Cpp17CopyConstructible*
|
| 490 |
+
requirements ([[cpp17.copyconstructible]]). The `X::pointer`,
|
| 491 |
`X::const_pointer`, `X::void_pointer`, and `X::const_void_pointer` types
|
| 492 |
+
shall meet the *Cpp17NullablePointer* requirements (
|
| 493 |
+
[[cpp17.nullablepointer]]). No constructor, comparison function, copy
|
| 494 |
+
operation, move operation, or swap operation on these pointer types
|
| 495 |
shall exit via an exception. `X::pointer` and `X::const_pointer` shall
|
| 496 |
+
also meet the requirements for a *Cpp17RandomAccessIterator*
|
| 497 |
+
[[random.access.iterators]] and the additional requirement that, when
|
| 498 |
+
`a` and `(a + n)` are dereferenceable pointer values for some integral
|
| 499 |
+
value `n`,
|
| 500 |
+
|
| 501 |
+
``` cpp
|
| 502 |
+
addressof(*(a + n)) == addressof(*a) + n
|
| 503 |
+
```
|
| 504 |
+
|
| 505 |
+
is `true`.
|
| 506 |
|
| 507 |
Let `x1` and `x2` denote objects of (possibly different) types
|
| 508 |
`X::void_pointer`, `X::const_void_pointer`, `X::pointer`, or
|
| 509 |
`X::const_pointer`. Then, `x1` and `x2` are *equivalently-valued*
|
| 510 |
pointer values, if and only if both `x1` and `x2` can be explicitly
|
|
|
|
| 543 |
the arguments for which its `construct` or `destroy` members may be
|
| 544 |
called. If a type cannot be used with a particular allocator, the
|
| 545 |
allocator class or the call to `construct` or `destroy` may fail to
|
| 546 |
instantiate.
|
| 547 |
|
| 548 |
+
If the alignment associated with a specific over-aligned type is not
|
| 549 |
+
supported by an allocator, instantiation of the allocator for that type
|
| 550 |
+
may fail. The allocator also may silently ignore the requested
|
| 551 |
+
alignment.
|
| 552 |
+
|
| 553 |
+
[*Note 3*: Additionally, the member function `allocate` for that type
|
| 554 |
+
may fail by throwing an object of type `bad_alloc`. — *end note*]
|
| 555 |
+
|
| 556 |
[*Example 1*:
|
| 557 |
|
| 558 |
The following is an allocator class template supporting the minimal
|
| 559 |
+
interface that meets the requirements of [[cpp17.allocator]]:
|
|
|
|
| 560 |
|
| 561 |
``` cpp
|
| 562 |
template<class Tp>
|
| 563 |
struct SimpleAllocator {
|
| 564 |
typedef Tp value_type;
|
| 565 |
SimpleAllocator(ctor args);
|
| 566 |
|
| 567 |
template<class T> SimpleAllocator(const SimpleAllocator<T>& other);
|
| 568 |
|
| 569 |
+
[[nodiscard]] Tp* allocate(std::size_t n);
|
| 570 |
void deallocate(Tp* p, std::size_t n);
|
| 571 |
};
|
| 572 |
|
| 573 |
template<class T, class U>
|
| 574 |
bool operator==(const SimpleAllocator<T>&, const SimpleAllocator<U>&);
|
|
|
|
| 576 |
bool operator!=(const SimpleAllocator<T>&, const SimpleAllocator<U>&);
|
| 577 |
```
|
| 578 |
|
| 579 |
— *end example*]
|
| 580 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 581 |
##### Allocator completeness requirements <a id="allocator.requirements.completeness">[[allocator.requirements.completeness]]</a>
|
| 582 |
|
| 583 |
+
If `X` is an allocator class for type `T`, `X` additionally meets the
|
| 584 |
+
allocator completeness requirements if, whether or not `T` is a complete
|
| 585 |
+
type:
|
| 586 |
|
| 587 |
- `X` is a complete type, and
|
| 588 |
+
- all the member types of `allocator_traits<X>` [[allocator.traits]]
|
| 589 |
other than `value_type` are complete types.
|
| 590 |
|
| 591 |
### Constraints on programs <a id="constraints">[[constraints]]</a>
|
| 592 |
|
| 593 |
#### Overview <a id="constraints.overview">[[constraints.overview]]</a>
|
| 594 |
|
| 595 |
+
Subclause [[constraints]] describes restrictions on C++ programs that
|
| 596 |
+
use the facilities of the C++ standard library. The following subclauses
|
| 597 |
+
specify constraints on the program’s use of namespaces
|
| 598 |
+
[[namespace.std]], its use of various reserved names [[reserved.names]],
|
| 599 |
+
its use of headers [[alt.headers]], its use of standard library classes
|
| 600 |
+
as base classes [[derived.classes]], its definitions of replacement
|
| 601 |
+
functions [[replacement.functions]], and its installation of handler
|
| 602 |
+
functions during execution [[handler.functions]].
|
| 603 |
|
| 604 |
#### Namespace use <a id="namespace.constraints">[[namespace.constraints]]</a>
|
| 605 |
|
| 606 |
##### Namespace `std` <a id="namespace.std">[[namespace.std]]</a>
|
| 607 |
|
| 608 |
+
Unless otherwise specified, the behavior of a C++ program is undefined
|
| 609 |
+
if it adds declarations or definitions to namespace `std` or to a
|
| 610 |
+
namespace within namespace `std`.
|
| 611 |
+
|
| 612 |
+
Unless explicitly prohibited, a program may add a template
|
| 613 |
+
specialization for any standard library class template to namespace
|
| 614 |
+
`std` provided that (a) the added declaration depends on at least one
|
| 615 |
+
program-defined type and (b) the specialization meets the standard
|
| 616 |
+
library requirements for the original template.[^21]
|
| 617 |
+
|
| 618 |
+
The behavior of a C++ program is undefined if it declares an explicit or
|
| 619 |
+
partial specialization of any standard library variable template, except
|
| 620 |
+
where explicitly permitted by the specification of that variable
|
| 621 |
+
template.
|
| 622 |
|
| 623 |
The behavior of a C++ program is undefined if it declares
|
| 624 |
|
| 625 |
- an explicit specialization of any member function of a standard
|
| 626 |
library class template, or
|
|
|
|
| 628 |
standard library class or class template, or
|
| 629 |
- an explicit or partial specialization of any member class template of
|
| 630 |
a standard library class or class template, or
|
| 631 |
- a deduction guide for any standard library class template.
|
| 632 |
|
| 633 |
+
A program may explicitly instantiate a class template defined in the
|
| 634 |
+
standard library only if the declaration (a) depends on the name of at
|
| 635 |
+
least one program-defined type and (b) the instantiation meets the
|
| 636 |
+
standard library requirements for the original template.
|
| 637 |
+
|
| 638 |
+
Let `F` denote a standard library function [[global.functions]], a
|
| 639 |
+
standard library static member function, or an instantiation of a
|
| 640 |
+
standard library function template. Unless `F` is designated an
|
| 641 |
+
*addressable function*, the behavior of a C++ program is unspecified
|
| 642 |
+
(possibly ill-formed) if it explicitly or implicitly attempts to form a
|
| 643 |
+
pointer to `F`.
|
| 644 |
+
|
| 645 |
+
[*Note 1*: Possible means of forming such pointers include application
|
| 646 |
+
of the unary `&` operator [[expr.unary.op]], `addressof`
|
| 647 |
+
[[specialized.addressof]], or a function-to-pointer standard conversion
|
| 648 |
+
[[conv.func]]. — *end note*]
|
| 649 |
+
|
| 650 |
+
Moreover, the behavior of a C++ program is unspecified (possibly
|
| 651 |
+
ill-formed) if it attempts to form a reference to `F` or if it attempts
|
| 652 |
+
to form a pointer-to-member designating either a standard library
|
| 653 |
+
non-static member function [[member.functions]] or an instantiation of a
|
| 654 |
+
standard library member function template.
|
| 655 |
+
|
| 656 |
+
Other than in namespace `std` or in a namespace within namespace `std`,
|
| 657 |
+
a program may provide an overload for any library function template
|
| 658 |
+
designated as a *customization point*, provided that (a) the overload’s
|
| 659 |
+
declaration depends on at least one user-defined type and (b) the
|
| 660 |
+
overload meets the standard library requirements for the customization
|
| 661 |
+
point. [^22]
|
| 662 |
+
|
| 663 |
+
[*Note 2*: This permits a (qualified or unqualified) call to the
|
| 664 |
+
customization point to invoke the most appropriate overload for the
|
| 665 |
+
given arguments. — *end note*]
|
| 666 |
|
| 667 |
A translation unit shall not declare namespace `std` to be an inline
|
| 668 |
+
namespace [[namespace.def]].
|
| 669 |
|
| 670 |
##### Namespace `posix` <a id="namespace.posix">[[namespace.posix]]</a>
|
| 671 |
|
| 672 |
The behavior of a C++ program is undefined if it adds declarations or
|
| 673 |
definitions to namespace `posix` or to a namespace within namespace
|
| 674 |
`posix` unless otherwise specified. The namespace `posix` is reserved
|
| 675 |
for use by ISO/IEC 9945 and other POSIX standards.
|
| 676 |
|
| 677 |
##### Namespaces for future standardization <a id="namespace.future">[[namespace.future]]</a>
|
| 678 |
|
| 679 |
+
Top-level namespaces whose *namespace-name* consists of `std` followed
|
| 680 |
+
by one or more *digit*s [[lex.name]] are reserved for future
|
| 681 |
+
standardization. The behavior of a C++ program is undefined if it adds
|
| 682 |
+
declarations or definitions to such a namespace.
|
| 683 |
|
| 684 |
+
[*Example 1*: The top-level namespace `std2` is reserved for use by
|
| 685 |
future revisions of this International Standard. — *end example*]
|
| 686 |
|
| 687 |
#### Reserved names <a id="reserved.names">[[reserved.names]]</a>
|
| 688 |
|
| 689 |
The C++ standard library reserves the following kinds of names:
|
|
|
|
| 700 |
|
| 701 |
In namespace `std`, the following names are reserved for previous
|
| 702 |
standardization:
|
| 703 |
|
| 704 |
- `auto_ptr`,
|
| 705 |
+
- `auto_ptr_ref`,
|
| 706 |
- `binary_function`,
|
| 707 |
+
- `binary_negate`,
|
| 708 |
- `bind1st`,
|
| 709 |
- `bind2nd`,
|
| 710 |
- `binder1st`,
|
| 711 |
- `binder2nd`,
|
| 712 |
- `const_mem_fun1_ref_t`,
|
| 713 |
- `const_mem_fun1_t`,
|
| 714 |
- `const_mem_fun_ref_t`,
|
| 715 |
- `const_mem_fun_t`,
|
| 716 |
+
- `get_temporary_buffer`,
|
| 717 |
- `get_unexpected`,
|
| 718 |
+
- `gets`,
|
| 719 |
+
- `is_literal_type`,
|
| 720 |
+
- `is_literal_type_v`,
|
| 721 |
- `mem_fun1_ref_t`,
|
| 722 |
- `mem_fun1_t`,
|
| 723 |
- `mem_fun_ref_t`,
|
| 724 |
- `mem_fun_ref`,
|
| 725 |
- `mem_fun_t`,
|
| 726 |
- `mem_fun`,
|
| 727 |
+
- `not1`,
|
| 728 |
+
- `not2`,
|
| 729 |
- `pointer_to_binary_function`,
|
| 730 |
- `pointer_to_unary_function`,
|
| 731 |
- `ptr_fun`,
|
| 732 |
- `random_shuffle`,
|
| 733 |
+
- `raw_storage_iterator`,
|
| 734 |
+
- `result_of`,
|
| 735 |
+
- `result_of_t`,
|
| 736 |
+
- `return_temporary_buffer`,
|
| 737 |
- `set_unexpected`,
|
| 738 |
- `unary_function`,
|
| 739 |
+
- `unary_negate`,
|
| 740 |
+
- `uncaught_exception`,
|
| 741 |
- `unexpected`, and
|
| 742 |
- `unexpected_handler`.
|
| 743 |
|
| 744 |
+
The following names are reserved as member types for previous
|
| 745 |
+
standardization, and may not be used as a name for object-like macros in
|
| 746 |
+
portable code:
|
| 747 |
+
|
| 748 |
+
- `argument_type`,
|
| 749 |
+
- `first_argument_type`,
|
| 750 |
+
- `io_state`,
|
| 751 |
+
- `open_mode`,
|
| 752 |
+
- `second_argument_type`, and
|
| 753 |
+
- `seek_dir`.
|
| 754 |
+
|
| 755 |
+
The name `stossc` is reserved as a member function for previous
|
| 756 |
+
standardization, and may not be used as a name for function-like macros
|
| 757 |
+
in portable code.
|
| 758 |
+
|
| 759 |
+
The header names `<ccomplex>`, `<ciso646>`, `<cstdalign>`, `<cstdbool>`,
|
| 760 |
+
and `<ctgmath>` are reserved for previous standardization.
|
| 761 |
+
|
| 762 |
##### Macro names <a id="macro.names">[[macro.names]]</a>
|
| 763 |
|
| 764 |
A translation unit that includes a standard library header shall not
|
| 765 |
`#define` or `#undef` names declared in any standard library header.
|
| 766 |
|
| 767 |
A translation unit shall not `#define` or `#undef` names lexically
|
| 768 |
+
identical to keywords, to the identifiers listed in
|
| 769 |
+
[[lex.name.special]], or to the *attribute-token*s described in
|
| 770 |
+
[[dcl.attr]], except that the names `likely` and `unlikely` may be
|
| 771 |
+
defined as function-like macros [[cpp.replace]].
|
| 772 |
|
| 773 |
##### External linkage <a id="extern.names">[[extern.names]]</a>
|
| 774 |
|
| 775 |
Each name declared as an object with external linkage in a header is
|
| 776 |
reserved to the implementation to designate that library object with
|
| 777 |
+
external linkage, [^23] both in namespace `std` and in the global
|
| 778 |
namespace.
|
| 779 |
|
| 780 |
Each global function signature declared with external linkage in a
|
| 781 |
header is reserved to the implementation to designate that function
|
| 782 |
+
signature with external linkage.[^24]
|
| 783 |
|
| 784 |
Each name from the C standard library declared with external linkage is
|
| 785 |
reserved to the implementation for use as a name with `extern "C"`
|
| 786 |
linkage, both in namespace `std` and in the global namespace.
|
| 787 |
|
| 788 |
Each function signature from the C standard library declared with
|
| 789 |
external linkage is reserved to the implementation for use as a function
|
| 790 |
+
signature with both `extern "C"` and `extern "C++"` linkage,[^25] or as
|
| 791 |
a name of namespace scope in the global namespace.
|
| 792 |
|
| 793 |
##### Types <a id="extern.types">[[extern.types]]</a>
|
| 794 |
|
| 795 |
+
For each type `T` from the C standard library, the types `::T` and
|
| 796 |
`std::T` are reserved to the implementation and, when defined, `::T`
|
| 797 |
shall be identical to `std::T`.
|
| 798 |
|
| 799 |
##### User-defined literal suffixes <a id="usrlit.suffix">[[usrlit.suffix]]</a>
|
| 800 |
|
| 801 |
+
Literal suffix identifiers [[over.literal]] that do not start with an
|
| 802 |
underscore are reserved for future standardization.
|
| 803 |
|
| 804 |
#### Headers <a id="alt.headers">[[alt.headers]]</a>
|
| 805 |
|
| 806 |
If a file with a name equivalent to the derived file name for one of the
|
| 807 |
C++ standard library headers is not provided as part of the
|
| 808 |
implementation, and a file with that name is placed in any of the
|
| 809 |
+
standard places for a source file to be included [[cpp.include]], the
|
| 810 |
behavior is undefined.
|
| 811 |
|
| 812 |
#### Derived classes <a id="derived.classes">[[derived.classes]]</a>
|
| 813 |
|
| 814 |
+
Virtual member function signatures defined for a base class in the C++
|
| 815 |
+
standard library may be overridden in a derived class defined in the
|
| 816 |
+
program [[class.virtual]].
|
| 817 |
|
| 818 |
#### Replacement functions <a id="replacement.functions">[[replacement.functions]]</a>
|
| 819 |
|
| 820 |
+
[[support]] through [[thread]] and [[depr]] describe the behavior of
|
| 821 |
+
numerous functions defined by the C++ standard library. Under some
|
| 822 |
+
circumstances, however, certain of these function descriptions also
|
| 823 |
+
apply to replacement functions defined in the program [[definitions]].
|
|
|
|
| 824 |
|
| 825 |
+
A C++ program may provide the definition for any of the following
|
| 826 |
+
dynamic memory allocation function signatures declared in header
|
| 827 |
+
`<new>` ([[basic.stc.dynamic]], [[new.syn]]):
|
| 828 |
|
| 829 |
``` cpp
|
| 830 |
operator new(std::size_t)
|
| 831 |
operator new(std::size_t, std::align_val_t)
|
| 832 |
operator new(std::size_t, const std::nothrow_t&)
|
|
|
|
| 857 |
operator delete[](void*, const std::nothrow_t&)
|
| 858 |
operator delete[](void*, std::align_val_t, const std::nothrow_t&)
|
| 859 |
```
|
| 860 |
|
| 861 |
The program’s definitions are used instead of the default versions
|
| 862 |
+
supplied by the implementation [[new.delete]]. Such replacement occurs
|
| 863 |
+
prior to program startup ([[basic.def.odr]], [[basic.start]]). The
|
| 864 |
+
program’s declarations shall not be specified as `inline`. No diagnostic
|
| 865 |
+
is required.
|
| 866 |
|
| 867 |
#### Handler functions <a id="handler.functions">[[handler.functions]]</a>
|
| 868 |
|
| 869 |
The C++ standard library provides a default version of the following
|
| 870 |
+
handler function [[support]]:
|
| 871 |
|
| 872 |
- `terminate_handler`
|
| 873 |
|
| 874 |
A C++ program may install different handler functions during execution,
|
| 875 |
by supplying a pointer to a function defined in the program or the
|
|
|
|
| 895 |
#### Other functions <a id="res.on.functions">[[res.on.functions]]</a>
|
| 896 |
|
| 897 |
In certain cases (replacement functions, handler functions, operations
|
| 898 |
on types used to instantiate standard library template components), the
|
| 899 |
C++ standard library depends on components supplied by a C++ program. If
|
| 900 |
+
these components do not meet their requirements, this document places no
|
| 901 |
+
requirements on the implementation.
|
| 902 |
|
| 903 |
In particular, the effects are undefined in the following cases:
|
| 904 |
|
| 905 |
+
- For replacement functions [[new.delete]], if the installed replacement
|
| 906 |
+
function does not implement the semantics of the applicable *Required
|
| 907 |
+
behavior:* paragraph.
|
| 908 |
+
- For handler functions ([[new.handler]], [[terminate.handler]]), if
|
| 909 |
the installed handler function does not implement the semantics of the
|
| 910 |
+
applicable *Required behavior:* paragraph.
|
| 911 |
+
- For types used as template arguments when instantiating a template
|
| 912 |
component, if the operations on the type do not implement the
|
| 913 |
semantics of the applicable *Requirements* subclause (
|
| 914 |
[[allocator.requirements]], [[container.requirements]],
|
| 915 |
[[iterator.requirements]], [[algorithms.requirements]],
|
| 916 |
[[numeric.requirements]]). Operations on such types can report a
|
| 917 |
failure by throwing an exception unless otherwise specified.
|
| 918 |
+
- If any replacement function or handler function or destructor
|
| 919 |
operation exits via an exception, unless specifically allowed in the
|
| 920 |
applicable *Required behavior:* paragraph.
|
| 921 |
+
- If an incomplete type [[basic.types]] is used as a template argument
|
| 922 |
+
when instantiating a template component or evaluating a concept,
|
| 923 |
+
unless specifically allowed for that component.
|
| 924 |
|
| 925 |
#### Function arguments <a id="res.on.arguments">[[res.on.arguments]]</a>
|
| 926 |
|
| 927 |
Each of the following applies to all arguments to functions defined in
|
| 928 |
the C++ standard library, unless explicitly stated otherwise.
|
|
|
|
| 937 |
fact valid.
|
| 938 |
- If a function argument binds to an rvalue reference parameter, the
|
| 939 |
implementation may assume that this parameter is a unique reference to
|
| 940 |
this argument. \[*Note 1*: If the parameter is a generic parameter of
|
| 941 |
the form `T&&` and an lvalue of type `A` is bound, the argument binds
|
| 942 |
+
to an lvalue reference [[temp.deduct.call]] and thus is not covered by
|
| 943 |
+
the previous sentence. — *end note*] \[*Note 2*: If a program casts
|
| 944 |
+
an lvalue to an xvalue while passing that lvalue to a library function
|
| 945 |
+
(e.g., by calling the function with the argument `std::move(x)`), the
|
| 946 |
+
program is effectively asking that function to treat that lvalue as a
|
| 947 |
+
temporary object. The implementation is free to optimize away aliasing
|
| 948 |
+
checks which might be needed if the argument was an
|
| 949 |
+
lvalue. — *end note*]
|
| 950 |
|
| 951 |
#### Library object access <a id="res.on.objects">[[res.on.objects]]</a>
|
| 952 |
|
| 953 |
The behavior of a program is undefined if calls to standard library
|
| 954 |
functions from different threads may introduce a data race. The
|
| 955 |
conditions under which this may occur are specified in
|
| 956 |
[[res.on.data.races]].
|
| 957 |
|
| 958 |
[*Note 1*: Modifying an object of a standard library type that is
|
| 959 |
shared between threads risks undefined behavior unless objects of that
|
| 960 |
+
type are explicitly specified as being shareable without data races or
|
| 961 |
the user supplies a locking mechanism. — *end note*]
|
| 962 |
|
| 963 |
If an object of a standard library type is accessed, and the beginning
|
| 964 |
+
of the object’s lifetime [[basic.life]] does not happen before the
|
| 965 |
access, or the access does not happen before the end of the object’s
|
| 966 |
lifetime, the behavior is undefined unless otherwise specified.
|
| 967 |
|
| 968 |
[*Note 2*: This applies even to objects such as mutexes intended for
|
| 969 |
thread synchronization. — *end note*]
|
| 970 |
|
| 971 |
+
#### Expects paragraph <a id="res.on.expects">[[res.on.expects]]</a>
|
| 972 |
|
| 973 |
+
Violation of any preconditions specified in a function’s
|
| 974 |
+
*Preconditions:* element results in undefined behavior.
|
| 975 |
+
|
| 976 |
+
#### Semantic requirements <a id="res.on.requirements">[[res.on.requirements]]</a>
|
| 977 |
+
|
| 978 |
+
A sequence `Args` of template arguments is said to *model* a concept `C`
|
| 979 |
+
if `Args` satisfies `C` [[temp.constr.decl]] and meets all semantic
|
| 980 |
+
requirements (if any) given in the specification of `C`.
|
| 981 |
+
|
| 982 |
+
If the validity or meaning of a program depends on whether a sequence of
|
| 983 |
+
template arguments models a concept, and the concept is satisfied but
|
| 984 |
+
not modeled, the program is ill-formed, no diagnostic required.
|
| 985 |
+
|
| 986 |
+
If the semantic requirements of a declaration’s constraints
|
| 987 |
+
[[structure.requirements]] are not modeled at the point of use, the
|
| 988 |
+
program is ill-formed, no diagnostic required.
|
| 989 |
|
| 990 |
### Conforming implementations <a id="conforming">[[conforming]]</a>
|
| 991 |
|
| 992 |
#### Overview <a id="conforming.overview">[[conforming.overview]]</a>
|
| 993 |
|
| 994 |
+
Subclause [[conforming]] describes the constraints upon, and latitude
|
| 995 |
+
of, implementations of the C++ standard library.
|
| 996 |
|
| 997 |
An implementation’s use of headers is discussed in [[res.on.headers]],
|
| 998 |
its use of macros in [[res.on.macro.definitions]], non-member functions
|
| 999 |
in [[global.functions]], member functions in [[member.functions]],
|
| 1000 |
data race avoidance in [[res.on.data.races]], access specifiers in
|
| 1001 |
[[protection.within.classes]], class derivation in [[derivation]], and
|
| 1002 |
exceptions in [[res.on.exception.handling]].
|
| 1003 |
|
| 1004 |
#### Headers <a id="res.on.headers">[[res.on.headers]]</a>
|
| 1005 |
|
| 1006 |
+
A C++ header may include other C++ headers. A C++ header shall provide
|
| 1007 |
+
the declarations and definitions that appear in its synopsis. A C++
|
| 1008 |
+
header shown in its synopsis as including other C++ headers shall
|
| 1009 |
+
provide the declarations and definitions that appear in the synopses of
|
| 1010 |
+
those other headers.
|
| 1011 |
|
| 1012 |
Certain types and macros are defined in more than one header. Every such
|
| 1013 |
entity shall be defined such that any header that defines it may be
|
| 1014 |
+
included after any other header that also defines it [[basic.def.odr]].
|
|
|
|
| 1015 |
|
| 1016 |
+
The C standard library headers [[depr.c.headers]] shall include only
|
| 1017 |
their corresponding C++ standard library header, as described in
|
| 1018 |
[[headers]].
|
| 1019 |
|
| 1020 |
#### Restrictions on macro definitions <a id="res.on.macro.definitions">[[res.on.macro.definitions]]</a>
|
| 1021 |
|
|
|
|
| 1028 |
stated otherwise.
|
| 1029 |
|
| 1030 |
#### Non-member functions <a id="global.functions">[[global.functions]]</a>
|
| 1031 |
|
| 1032 |
It is unspecified whether any non-member functions in the C++ standard
|
| 1033 |
+
library are defined as inline [[dcl.inline]].
|
| 1034 |
|
| 1035 |
+
A call to a non-member function signature described in [[support]]
|
| 1036 |
+
through [[thread]] and [[depr]] shall behave as if the implementation
|
| 1037 |
+
declared no additional non-member function signatures.[^26]
|
|
|
|
| 1038 |
|
| 1039 |
An implementation shall not declare a non-member function signature with
|
| 1040 |
additional default arguments.
|
| 1041 |
|
| 1042 |
Unless otherwise specified, calls made by functions in the standard
|
| 1043 |
library to non-operator, non-member functions do not use functions from
|
| 1044 |
+
another namespace which are found through argument-dependent name lookup
|
| 1045 |
+
[[basic.lookup.argdep]].
|
| 1046 |
|
| 1047 |
[*Note 1*:
|
| 1048 |
|
| 1049 |
The phrase “unless otherwise specified” applies to cases such as the
|
| 1050 |
+
swappable with requirements [[swappable.requirements]]. The exception
|
| 1051 |
for overloaded operators allows argument-dependent lookup in cases like
|
| 1052 |
+
that of `ostream_iterator::operator=` [[ostream.iterator.ops]]:
|
| 1053 |
|
| 1054 |
*Effects:*
|
| 1055 |
|
| 1056 |
``` cpp
|
| 1057 |
*out_stream << value;
|
|
|
|
| 1063 |
— *end note*]
|
| 1064 |
|
| 1065 |
#### Member functions <a id="member.functions">[[member.functions]]</a>
|
| 1066 |
|
| 1067 |
It is unspecified whether any member functions in the C++ standard
|
| 1068 |
+
library are defined as inline [[dcl.inline]].
|
| 1069 |
|
| 1070 |
For a non-virtual member function described in the C++ standard library,
|
| 1071 |
an implementation may declare a different set of member function
|
| 1072 |
signatures, provided that any call to the member function that would
|
| 1073 |
select an overload from the set of declarations described in this
|
| 1074 |
+
document behaves as if that overload were selected.
|
| 1075 |
|
| 1076 |
[*Note 1*: For instance, an implementation may add parameters with
|
| 1077 |
default values, or replace a member function with default arguments with
|
| 1078 |
two or more member functions with equivalent behavior, or add additional
|
| 1079 |
signatures for a member function name. — *end note*]
|
| 1080 |
|
| 1081 |
+
#### Friend functions <a id="hidden.friends">[[hidden.friends]]</a>
|
| 1082 |
+
|
| 1083 |
+
Whenever this document specifies a friend declaration of a function or
|
| 1084 |
+
function template within a class or class template definition, that
|
| 1085 |
+
declaration shall be the only declaration of that function or function
|
| 1086 |
+
template provided by an implementation.
|
| 1087 |
+
|
| 1088 |
+
[*Note 1*: In particular, an implementation is not allowed to provide
|
| 1089 |
+
an additional declaration of that function or function template at
|
| 1090 |
+
namespace scope. — *end note*]
|
| 1091 |
+
|
| 1092 |
+
[*Note 2*: Such a friend function or function template declaration is
|
| 1093 |
+
known as a hidden friend, as it is visible neither to ordinary
|
| 1094 |
+
unqualified lookup [[basic.lookup.unqual]] nor to qualified lookup
|
| 1095 |
+
[[basic.lookup.qual]]. — *end note*]
|
| 1096 |
+
|
| 1097 |
#### Constexpr functions and constructors <a id="constexpr.functions">[[constexpr.functions]]</a>
|
| 1098 |
|
| 1099 |
+
This document explicitly requires that certain standard library
|
| 1100 |
+
functions are `constexpr` [[dcl.constexpr]]. An implementation shall not
|
| 1101 |
+
declare any standard library function signature as `constexpr` except
|
| 1102 |
+
for those where it is explicitly required. Within any header that
|
| 1103 |
+
provides any non-defining declarations of constexpr functions or
|
| 1104 |
+
constructors an implementation shall provide corresponding definitions.
|
|
|
|
| 1105 |
|
| 1106 |
#### Requirements for stable algorithms <a id="algorithm.stable">[[algorithm.stable]]</a>
|
| 1107 |
|
| 1108 |
When the requirements for an algorithm state that it is “stable” without
|
| 1109 |
further elaboration, it means:
|
| 1110 |
|
| 1111 |
+
- For the sort algorithms the relative order of equivalent elements is
|
| 1112 |
preserved.
|
| 1113 |
+
- For the remove and copy algorithms the relative order of the elements
|
| 1114 |
+
that are not removed is preserved.
|
| 1115 |
+
- For the merge algorithms, for equivalent elements in the original two
|
| 1116 |
+
ranges, the elements from the first range (preserving their original
|
| 1117 |
+
order) precede the elements from the second range (preserving their
|
| 1118 |
+
original order).
|
| 1119 |
|
| 1120 |
#### Reentrancy <a id="reentrancy">[[reentrancy]]</a>
|
| 1121 |
|
| 1122 |
+
Except where explicitly specified in this document, it is
|
| 1123 |
*implementation-defined* which functions in the C++ standard library may
|
| 1124 |
be recursively reentered.
|
| 1125 |
|
| 1126 |
#### Data race avoidance <a id="res.on.data.races">[[res.on.data.races]]</a>
|
| 1127 |
|
| 1128 |
+
This subclause specifies requirements that implementations shall meet to
|
| 1129 |
+
prevent data races [[intro.multithread]]. Every standard library
|
| 1130 |
function shall meet each requirement unless otherwise specified.
|
| 1131 |
Implementations may prevent data races in cases other than those
|
| 1132 |
specified below.
|
| 1133 |
|
| 1134 |
A C++ standard library function shall not directly or indirectly access
|
| 1135 |
+
objects [[intro.multithread]] accessible by threads other than the
|
| 1136 |
current thread unless the objects are accessed directly or indirectly
|
| 1137 |
via the function’s arguments, including `this`.
|
| 1138 |
|
| 1139 |
A C++ standard library function shall not directly or indirectly modify
|
| 1140 |
+
objects [[intro.multithread]] accessible by threads other than the
|
| 1141 |
current thread unless the objects are accessed directly or indirectly
|
| 1142 |
via the function’s non-const arguments, including `this`.
|
| 1143 |
|
| 1144 |
+
[*Note 1*: This means, for example, that implementations can’t use an
|
| 1145 |
+
object with static storage duration for internal purposes without
|
| 1146 |
+
synchronization because it could cause a data race even in programs that
|
| 1147 |
+
do not explicitly share objects between threads. — *end note*]
|
| 1148 |
|
| 1149 |
A C++ standard library function shall not access objects indirectly
|
| 1150 |
accessible via its arguments or via elements of its container arguments
|
| 1151 |
except by invoking functions required by its specification on those
|
| 1152 |
container elements.
|
|
|
|
| 1163 |
the objects are not visible to users and are protected against data
|
| 1164 |
races.
|
| 1165 |
|
| 1166 |
Unless otherwise specified, C++ standard library functions shall perform
|
| 1167 |
all operations solely within the current thread if those operations have
|
| 1168 |
+
effects that are visible [[intro.multithread]] to users.
|
| 1169 |
|
| 1170 |
[*Note 3*: This allows implementations to parallelize operations if
|
| 1171 |
there are no visible side effects. — *end note*]
|
| 1172 |
|
| 1173 |
#### Protection within classes <a id="protection.within.classes">[[protection.within.classes]]</a>
|
| 1174 |
|
| 1175 |
It is unspecified whether any function signature or class described in
|
| 1176 |
+
[[support]] through [[thread]] and [[depr]] is a friend of another class
|
| 1177 |
+
in the C++ standard library.
|
| 1178 |
|
| 1179 |
#### Derived classes <a id="derivation">[[derivation]]</a>
|
| 1180 |
|
| 1181 |
+
An implementation may derive any class in the C++ standard library from
|
| 1182 |
+
a class with a name reserved to the implementation.
|
| 1183 |
|
| 1184 |
Certain classes defined in the C++ standard library are required to be
|
| 1185 |
+
derived from other classes in the C++ standard library. An
|
| 1186 |
+
implementation may derive such a class directly from the required base
|
| 1187 |
+
or indirectly through a hierarchy of base classes with names reserved to
|
| 1188 |
+
the implementation.
|
| 1189 |
|
| 1190 |
In any case:
|
| 1191 |
|
| 1192 |
- Every base class described as `virtual` shall be virtual;
|
| 1193 |
- Every base class not specified as `virtual` shall not be virtual;
|
|
|
|
| 1207 |
|
| 1208 |
Functions from the C standard library shall not throw exceptions [^28]
|
| 1209 |
except when such a function calls a program-supplied function that
|
| 1210 |
throws an exception.[^29]
|
| 1211 |
|
| 1212 |
+
Destructor operations defined in the C++ standard library shall not
|
| 1213 |
+
throw exceptions. Every destructor in the C++ standard library shall
|
| 1214 |
+
behave as if it had a non-throwing exception specification.
|
| 1215 |
|
| 1216 |
Functions defined in the C++ standard library that do not have a
|
| 1217 |
*Throws:* paragraph but do have a potentially-throwing exception
|
| 1218 |
specification may throw *implementation-defined* exceptions. [^30]
|
| 1219 |
Implementations should report errors by throwing exceptions of or
|
|
|
|
| 1225 |
|
| 1226 |
#### Restrictions on storage of pointers <a id="res.on.pointer.storage">[[res.on.pointer.storage]]</a>
|
| 1227 |
|
| 1228 |
Objects constructed by the standard library that may hold a
|
| 1229 |
user-supplied pointer value or an integer of type `std::intptr_t` shall
|
| 1230 |
+
store such values in a traceable pointer location
|
| 1231 |
+
[[basic.stc.dynamic.safety]].
|
| 1232 |
|
| 1233 |
[*Note 1*: Other libraries are strongly encouraged to do the same,
|
| 1234 |
since not doing so may result in accidental use of pointers that are not
|
| 1235 |
safely derived. Libraries that store pointers outside the user’s address
|
| 1236 |
space should make it appear that they are stored and retrieved from a
|
| 1237 |
traceable pointer location. — *end note*]
|
| 1238 |
|
| 1239 |
#### Value of error codes <a id="value.error.codes">[[value.error.codes]]</a>
|
| 1240 |
|
| 1241 |
Certain functions in the C++ standard library report errors via a
|
| 1242 |
+
`std::error_code` [[syserr.errcode.overview]] object. That object’s
|
| 1243 |
`category()` member shall return `std::system_category()` for errors
|
| 1244 |
originating from the operating system, or a reference to an
|
| 1245 |
*implementation-defined* `error_category` object for errors originating
|
| 1246 |
elsewhere. The implementation shall define the possible values of
|
| 1247 |
`value()` for each of these error categories.
|
| 1248 |
|
| 1249 |
[*Example 1*: For operating systems that are based on POSIX,
|
| 1250 |
+
implementations should define the `std::system_category()` values as
|
| 1251 |
+
identical to the POSIX `errno` values, with additional values as defined
|
| 1252 |
+
by the operating system’s documentation. Implementations for operating
|
| 1253 |
+
systems that are not based on POSIX should define values identical to
|
| 1254 |
+
the operating system’s values. For errors that do not originate from the
|
| 1255 |
+
operating system, the implementation may provide enums for the
|
| 1256 |
+
associated values. — *end example*]
|
| 1257 |
|
| 1258 |
#### Moved-from state of library types <a id="lib.types.movedfrom">[[lib.types.movedfrom]]</a>
|
| 1259 |
|
| 1260 |
+
Objects of types defined in the C++ standard library may be moved from
|
| 1261 |
+
[[class.copy.ctor]]. Move operations may be explicitly specified or
|
| 1262 |
implicitly generated. Unless otherwise specified, such moved-from
|
| 1263 |
objects shall be placed in a valid but unspecified state.
|
| 1264 |
|
| 1265 |
<!-- Link reference definitions -->
|
| 1266 |
[alg.c.library]: algorithms.md#alg.c.library
|
| 1267 |
[alg.sorting]: algorithms.md#alg.sorting
|
| 1268 |
[algorithm.stable]: #algorithm.stable
|
| 1269 |
[algorithms]: algorithms.md#algorithms
|
| 1270 |
[algorithms.requirements]: algorithms.md#algorithms.requirements
|
| 1271 |
+
[alloc.errors]: support.md#alloc.errors
|
| 1272 |
+
[allocator.req.var]: #allocator.req.var
|
| 1273 |
[allocator.requirements]: #allocator.requirements
|
| 1274 |
[allocator.requirements.completeness]: #allocator.requirements.completeness
|
| 1275 |
[allocator.traits]: utilities.md#allocator.traits
|
| 1276 |
[alt.headers]: #alt.headers
|
| 1277 |
[atomics]: atomics.md#atomics
|
| 1278 |
+
[atomics.alias]: atomics.md#atomics.alias
|
| 1279 |
+
[atomics.lockfree]: atomics.md#atomics.lockfree
|
| 1280 |
+
[bad.alloc]: support.md#bad.alloc
|
| 1281 |
[basic.def.odr]: basic.md#basic.def.odr
|
| 1282 |
[basic.fundamental]: basic.md#basic.fundamental
|
| 1283 |
[basic.life]: basic.md#basic.life
|
| 1284 |
[basic.link]: basic.md#basic.link
|
| 1285 |
[basic.lookup.argdep]: basic.md#basic.lookup.argdep
|
| 1286 |
+
[basic.lookup.qual]: basic.md#basic.lookup.qual
|
| 1287 |
+
[basic.lookup.unqual]: basic.md#basic.lookup.unqual
|
| 1288 |
[basic.scope.namespace]: basic.md#basic.scope.namespace
|
| 1289 |
[basic.start]: basic.md#basic.start
|
| 1290 |
[basic.stc.dynamic]: basic.md#basic.stc.dynamic
|
| 1291 |
[basic.stc.dynamic.safety]: basic.md#basic.stc.dynamic.safety
|
| 1292 |
[basic.types]: basic.md#basic.types
|
| 1293 |
+
[bit]: numerics.md#bit
|
| 1294 |
[bitmask.types]: #bitmask.types
|
| 1295 |
[byte.strings]: #byte.strings
|
| 1296 |
+
[c.annex.k.names]: #c.annex.k.names
|
|
|
|
| 1297 |
[character.seq]: #character.seq
|
| 1298 |
+
[class.copy.assign]: class.md#class.copy.assign
|
| 1299 |
+
[class.copy.ctor]: class.md#class.copy.ctor
|
| 1300 |
+
[class.dtor]: class.md#class.dtor
|
|
|
|
| 1301 |
[class.mem]: class.md#class.mem
|
| 1302 |
[class.mfct]: class.md#class.mfct
|
| 1303 |
[class.this]: class.md#class.this
|
| 1304 |
[class.virtual]: class.md#class.virtual
|
| 1305 |
+
[cmp]: support.md#cmp
|
| 1306 |
[compliance]: #compliance
|
| 1307 |
+
[concept.destructible]: concepts.md#concept.destructible
|
| 1308 |
+
[concept.invocable]: concepts.md#concept.invocable
|
| 1309 |
+
[concept.totallyordered]: concepts.md#concept.totallyordered
|
| 1310 |
+
[concepts]: concepts.md#concepts
|
| 1311 |
+
[concepts.equality]: concepts.md#concepts.equality
|
| 1312 |
+
[concepts.object]: concepts.md#concepts.object
|
| 1313 |
[conforming]: #conforming
|
| 1314 |
[conforming.overview]: #conforming.overview
|
| 1315 |
[constexpr.functions]: #constexpr.functions
|
| 1316 |
[constraints]: #constraints
|
| 1317 |
[constraints.overview]: #constraints.overview
|
| 1318 |
[container.requirements]: containers.md#container.requirements
|
| 1319 |
[containers]: containers.md#containers
|
| 1320 |
[contents]: #contents
|
| 1321 |
+
[conv]: expr.md#conv
|
| 1322 |
+
[conv.func]: expr.md#conv.func
|
| 1323 |
[conventions]: #conventions
|
| 1324 |
[cpp.include]: cpp.md#cpp.include
|
| 1325 |
+
[cpp.replace]: cpp.md#cpp.replace
|
| 1326 |
+
[cpp17.allocator]: #cpp17.allocator
|
| 1327 |
+
[cpp17.copyassignable]: #cpp17.copyassignable
|
| 1328 |
+
[cpp17.copyconstructible]: #cpp17.copyconstructible
|
| 1329 |
+
[cpp17.destructible]: #cpp17.destructible
|
| 1330 |
+
[cpp17.hash]: #cpp17.hash
|
| 1331 |
+
[cpp17.moveassignable]: #cpp17.moveassignable
|
| 1332 |
+
[cpp17.nullablepointer]: #cpp17.nullablepointer
|
| 1333 |
+
[cstdint]: support.md#cstdint
|
| 1334 |
+
[customization.point.object]: #customization.point.object
|
| 1335 |
[dcl.array]: dcl.md#dcl.array
|
| 1336 |
[dcl.attr]: dcl.md#dcl.attr
|
| 1337 |
[dcl.constexpr]: dcl.md#dcl.constexpr
|
| 1338 |
[dcl.fct.default]: dcl.md#dcl.fct.default
|
| 1339 |
[dcl.init]: dcl.md#dcl.init
|
| 1340 |
[dcl.init.list]: dcl.md#dcl.init.list
|
| 1341 |
[dcl.inline]: dcl.md#dcl.inline
|
| 1342 |
[dcl.link]: dcl.md#dcl.link
|
| 1343 |
+
[dcl.pre]: dcl.md#dcl.pre
|
| 1344 |
[definitions]: #definitions
|
| 1345 |
[depr]: future.md#depr
|
| 1346 |
[depr.c.headers]: future.md#depr.c.headers
|
|
|
|
|
|
|
| 1347 |
[derivation]: #derivation
|
| 1348 |
[derived.classes]: #derived.classes
|
| 1349 |
[description]: #description
|
| 1350 |
[diagnostics]: diagnostics.md#diagnostics
|
| 1351 |
[enumerated.types]: #enumerated.types
|
| 1352 |
[except]: except.md#except
|
| 1353 |
+
[except.spec]: except.md#except.spec
|
| 1354 |
+
[expos.only.func]: #expos.only.func
|
| 1355 |
[expos.only.types]: #expos.only.types
|
| 1356 |
[expr.cond]: expr.md#expr.cond
|
| 1357 |
[expr.const]: expr.md#expr.const
|
| 1358 |
[expr.delete]: expr.md#expr.delete
|
| 1359 |
[expr.eq]: expr.md#expr.eq
|
| 1360 |
[expr.new]: expr.md#expr.new
|
| 1361 |
[expr.rel]: expr.md#expr.rel
|
| 1362 |
+
[expr.spaceship]: expr.md#expr.spaceship
|
| 1363 |
+
[expr.unary.op]: expr.md#expr.unary.op
|
| 1364 |
[extern.names]: #extern.names
|
| 1365 |
[extern.types]: #extern.types
|
| 1366 |
[function.objects]: utilities.md#function.objects
|
| 1367 |
[functions.within.classes]: #functions.within.classes
|
| 1368 |
[global.functions]: #global.functions
|
| 1369 |
[handler.functions]: #handler.functions
|
| 1370 |
[hash.requirements]: #hash.requirements
|
| 1371 |
[headers]: #headers
|
| 1372 |
+
[headers.cpp]: #headers.cpp
|
| 1373 |
+
[headers.cpp.c]: #headers.cpp.c
|
| 1374 |
+
[headers.cpp.fs]: #headers.cpp.fs
|
| 1375 |
+
[hidden.friends]: #hidden.friends
|
| 1376 |
[input.output]: input.md#input.output
|
| 1377 |
[intro.compliance]: intro.md#intro.compliance
|
| 1378 |
[intro.defs]: intro.md#intro.defs
|
| 1379 |
+
[intro.execution]: basic.md#intro.execution
|
| 1380 |
+
[intro.multithread]: basic.md#intro.multithread
|
| 1381 |
[intro.refs]: intro.md#intro.refs
|
| 1382 |
[iterator.requirements]: iterators.md#iterator.requirements
|
|
|
|
| 1383 |
[iterators]: iterators.md#iterators
|
| 1384 |
+
[lex.name]: lex.md#lex.name
|
| 1385 |
+
[lex.name.special]: #lex.name.special
|
| 1386 |
[lex.phases]: lex.md#lex.phases
|
| 1387 |
+
[lex.separate]: lex.md#lex.separate
|
| 1388 |
[lib.types.movedfrom]: #lib.types.movedfrom
|
| 1389 |
[library]: #library
|
| 1390 |
[library.c]: #library.c
|
| 1391 |
+
[library.categories]: #library.categories
|
| 1392 |
[library.general]: #library.general
|
| 1393 |
[locales]: localization.md#locales
|
| 1394 |
[localization]: localization.md#localization
|
| 1395 |
[macro.names]: #macro.names
|
| 1396 |
[member.functions]: #member.functions
|
| 1397 |
[meta]: utilities.md#meta
|
| 1398 |
+
[module.import]: module.md#module.import
|
| 1399 |
[multibyte.strings]: #multibyte.strings
|
| 1400 |
[namespace.constraints]: #namespace.constraints
|
| 1401 |
[namespace.def]: dcl.md#namespace.def
|
| 1402 |
[namespace.future]: #namespace.future
|
| 1403 |
[namespace.posix]: #namespace.posix
|
| 1404 |
[namespace.std]: #namespace.std
|
| 1405 |
[namespace.udecl]: dcl.md#namespace.udecl
|
| 1406 |
+
[new.delete]: support.md#new.delete
|
| 1407 |
+
[new.handler]: support.md#new.handler
|
| 1408 |
+
[new.syn]: support.md#new.syn
|
| 1409 |
[nullablepointer.requirements]: #nullablepointer.requirements
|
| 1410 |
[numeric.requirements]: numerics.md#numeric.requirements
|
| 1411 |
[numerics]: numerics.md#numerics
|
| 1412 |
[objects.within.classes]: #objects.within.classes
|
| 1413 |
[organization]: #organization
|
|
|
|
| 1415 |
[over.literal]: over.md#over.literal
|
| 1416 |
[over.match]: over.md#over.match
|
| 1417 |
[over.oper]: over.md#over.oper
|
| 1418 |
[protection.within.classes]: #protection.within.classes
|
| 1419 |
[random.access.iterators]: iterators.md#random.access.iterators
|
| 1420 |
+
[ranges]: ranges.md#ranges
|
| 1421 |
[re]: re.md#re
|
| 1422 |
[reentrancy]: #reentrancy
|
| 1423 |
[replacement.functions]: #replacement.functions
|
| 1424 |
[requirements]: #requirements
|
| 1425 |
[res.on.arguments]: #res.on.arguments
|
| 1426 |
[res.on.data.races]: #res.on.data.races
|
| 1427 |
[res.on.exception.handling]: #res.on.exception.handling
|
| 1428 |
+
[res.on.expects]: #res.on.expects
|
| 1429 |
[res.on.functions]: #res.on.functions
|
| 1430 |
[res.on.headers]: #res.on.headers
|
| 1431 |
[res.on.macro.definitions]: #res.on.macro.definitions
|
| 1432 |
[res.on.objects]: #res.on.objects
|
| 1433 |
[res.on.pointer.storage]: #res.on.pointer.storage
|
| 1434 |
+
[res.on.requirements]: #res.on.requirements
|
| 1435 |
[reserved.names]: #reserved.names
|
| 1436 |
+
[specialized.addressof]: utilities.md#specialized.addressof
|
| 1437 |
[std.exceptions]: diagnostics.md#std.exceptions
|
| 1438 |
+
[stmt.return]: stmt.md#stmt.return
|
| 1439 |
[stream.types]: input.md#stream.types
|
| 1440 |
[strings]: strings.md#strings
|
| 1441 |
[structure]: #structure
|
| 1442 |
[structure.elements]: #structure.elements
|
| 1443 |
[structure.requirements]: #structure.requirements
|
| 1444 |
[structure.see.also]: #structure.see.also
|
| 1445 |
[structure.specifications]: #structure.specifications
|
| 1446 |
[structure.summary]: #structure.summary
|
| 1447 |
+
[support]: support.md#support
|
| 1448 |
+
[support.coroutine]: support.md#support.coroutine
|
| 1449 |
+
[support.dynamic]: support.md#support.dynamic
|
| 1450 |
+
[support.exception]: support.md#support.exception
|
| 1451 |
+
[support.initlist]: support.md#support.initlist
|
| 1452 |
+
[support.limits]: support.md#support.limits
|
| 1453 |
+
[support.rtti]: support.md#support.rtti
|
| 1454 |
+
[support.runtime]: support.md#support.runtime
|
| 1455 |
+
[support.srcloc]: support.md#support.srcloc
|
| 1456 |
+
[support.start.term]: support.md#support.start.term
|
| 1457 |
+
[support.types]: support.md#support.types
|
| 1458 |
[swappable.requirements]: #swappable.requirements
|
| 1459 |
[syserr]: diagnostics.md#syserr
|
| 1460 |
[syserr.errcode.overview]: diagnostics.md#syserr.errcode.overview
|
| 1461 |
+
[tab:allocator.req.var]: #tab:allocator.req.var
|
| 1462 |
+
[tab:cpp17.allocator]: #tab:cpp17.allocator
|
| 1463 |
+
[tab:cpp17.destructible]: #tab:cpp17.destructible
|
| 1464 |
+
[tab:cpp17.equalitycomparable]: #tab:cpp17.equalitycomparable
|
| 1465 |
+
[temp]: temp.md#temp
|
| 1466 |
+
[temp.concept]: temp.md#temp.concept
|
| 1467 |
+
[temp.constr.decl]: temp.md#temp.constr.decl
|
| 1468 |
+
[temp.constr.order]: temp.md#temp.constr.order
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1469 |
[temp.deduct.call]: temp.md#temp.deduct.call
|
| 1470 |
+
[temp.func.order]: temp.md#temp.func.order
|
| 1471 |
[template.bitset]: utilities.md#template.bitset
|
| 1472 |
+
[terminate.handler]: support.md#terminate.handler
|
| 1473 |
[thread]: thread.md#thread
|
| 1474 |
+
[time]: time.md#time
|
| 1475 |
[type.descriptions]: #type.descriptions
|
| 1476 |
[type.descriptions.general]: #type.descriptions.general
|
| 1477 |
[using]: #using
|
| 1478 |
[using.headers]: #using.headers
|
| 1479 |
[using.linkage]: #using.linkage
|
| 1480 |
[using.overview]: #using.overview
|
| 1481 |
[usrlit.suffix]: #usrlit.suffix
|
| 1482 |
[utilities]: utilities.md#utilities
|
|
|
|
| 1483 |
[utility.arg.requirements]: #utility.arg.requirements
|
| 1484 |
[utility.requirements]: #utility.requirements
|
| 1485 |
[value.error.codes]: #value.error.codes
|
| 1486 |
[zombie.names]: #zombie.names
|
| 1487 |
|
|
|
|
| 1494 |
|
| 1495 |
[^3]: To save space, items that do not apply to a class are omitted. For
|
| 1496 |
example, if a class does not specify any comparison functions, there
|
| 1497 |
will be no “Comparison functions” subclause.
|
| 1498 |
|
| 1499 |
+
[^4]: To save space, elements that do not apply to a function are
|
| 1500 |
+
omitted. For example, if a function specifies no preconditions,
|
| 1501 |
+
there will be no *Preconditions:* element.
|
| 1502 |
|
| 1503 |
[^5]: This simplifies the presentation of complexity requirements in
|
| 1504 |
some cases.
|
| 1505 |
|
| 1506 |
[^6]: Examples from [[utility.requirements]] include:
|
| 1507 |
+
*Cpp17EqualityComparable*, *Cpp17LessThanComparable*,
|
| 1508 |
+
*Cpp17CopyConstructible*. Examples from [[iterator.requirements]]
|
| 1509 |
+
include: *Cpp17InputIterator*, *Cpp17ForwardIterator*.
|
| 1510 |
|
| 1511 |
+
[^7]: Such as an integer type, with constant integer values
|
| 1512 |
+
[[basic.fundamental]].
|
| 1513 |
|
| 1514 |
+
[^8]: declared in `<clocale>`.
|
| 1515 |
|
| 1516 |
[^9]: Many of the objects manipulated by function signatures declared in
|
| 1517 |
+
`<cstring>` are character sequences or NTBSs. The size of some of
|
| 1518 |
+
these character sequences is limited by a length value, maintained
|
| 1519 |
+
separately from the character sequence.
|
| 1520 |
|
| 1521 |
+
[^10]: A *string-literal*, such as `"abc"`, is a static NTBS.
|
| 1522 |
|
| 1523 |
[^11]: An NTBS that contains characters only from the basic execution
|
| 1524 |
character set is also an NTMBS. Each multibyte character then
|
| 1525 |
consists of a single byte.
|
| 1526 |
|
| 1527 |
+
[^12]: The C standard library headers [[depr.c.headers]] also define
|
| 1528 |
+
names within the global namespace, while the C++ headers for C
|
| 1529 |
+
library facilities [[headers]] may also define names within the
|
| 1530 |
global namespace.
|
| 1531 |
|
| 1532 |
[^13]: This gives implementers freedom to use inline namespaces to
|
| 1533 |
support multiple configurations of the library.
|
| 1534 |
|
| 1535 |
[^14]: A header is not necessarily a source file, nor are the sequences
|
| 1536 |
delimited by `<` and `>` in header names necessarily valid source
|
| 1537 |
+
file names [[cpp.include]].
|
| 1538 |
|
| 1539 |
[^15]: It is intentional that there is no C++ header for any of these C
|
| 1540 |
headers: `<stdatomic.h>`, `<stdnoreturn.h>`, `<threads.h>`.
|
| 1541 |
|
| 1542 |
[^16]: This disallows the practice, allowed in C, of providing a masking
|
| 1543 |
macro in addition to the function prototype. The only way to achieve
|
| 1544 |
equivalent inline behavior in C++ is to provide a definition as an
|
| 1545 |
extern inline function.
|
| 1546 |
|
| 1547 |
+
[^17]: In particular, including the standard header `<iso646.h>` has no
|
| 1548 |
+
effect.
|
| 1549 |
|
| 1550 |
[^18]: The `".h"` headers dump all their names into the global
|
| 1551 |
namespace, whereas the newer forms keep their names in namespace
|
| 1552 |
`std`. Therefore, the newer forms are the preferred forms for all
|
| 1553 |
uses except for C++ programs which are intended to be strictly
|
|
|
|
| 1559 |
from the C standard library is by including the header that declares
|
| 1560 |
it, notwithstanding the latitude granted in 7.1.4 of the C Standard.
|
| 1561 |
|
| 1562 |
[^21]: Any library code that instantiates other library templates must
|
| 1563 |
be prepared to work adequately with any user-supplied specialization
|
| 1564 |
+
that meets the minimum requirements of this document.
|
| 1565 |
|
| 1566 |
+
[^22]: Any library customization point must be prepared to work
|
| 1567 |
+
adequately with any user-defined overload that meets the minimum
|
| 1568 |
+
requirements of this document. Therefore an implementation may
|
| 1569 |
+
elect, under the as-if rule [[intro.execution]], to provide any
|
| 1570 |
+
customization point in the form of an instantiated function object
|
| 1571 |
+
[[function.objects]] even though the customization point’s
|
| 1572 |
+
specification is in the form of a function template. The template
|
| 1573 |
+
parameters of each such function object and the function parameters
|
| 1574 |
+
and return type of the object’s `operator()` must match those of the
|
| 1575 |
+
corresponding customization point’s specification.
|
| 1576 |
+
|
| 1577 |
+
[^23]: The list of such reserved names includes `errno`, declared or
|
| 1578 |
defined in `<cerrno>`.
|
| 1579 |
|
| 1580 |
+
[^24]: The list of such reserved function signatures with external
|
| 1581 |
linkage includes `setjmp(jmp_buf)`, declared or defined in
|
| 1582 |
`<csetjmp>`, and `va_end(va_list)`, declared or defined in
|
| 1583 |
`<cstdarg>`.
|
| 1584 |
|
| 1585 |
+
[^25]: The function signatures declared in `<cuchar>`, `<cwchar>`, and
|
| 1586 |
`<cwctype>` are always reserved, notwithstanding the restrictions
|
| 1587 |
imposed in subclause 4.5.1 of Amendment 1 to the C Standard for
|
| 1588 |
these headers.
|
| 1589 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1590 |
[^26]: A valid C++ program always calls the expected library non-member
|
| 1591 |
function. An implementation may also define additional non-member
|
| 1592 |
functions that would otherwise not be called by a valid C++ program.
|
| 1593 |
|
| 1594 |
[^27]: There is an implicit exception to this rule for types that are
|
| 1595 |
+
described as synonyms for basic integral types, such as `size_t`
|
| 1596 |
+
[[support.types]] and `streamoff` [[stream.types]].
|
| 1597 |
|
| 1598 |
[^28]: That is, the C library functions can all be treated as if they
|
| 1599 |
are marked `noexcept`. This allows implementations to make
|
| 1600 |
performance optimizations based on the absence of exceptions at
|
| 1601 |
runtime.
|
| 1602 |
|
| 1603 |
+
[^29]: The functions `qsort()` and `bsearch()` [[alg.c.library]] meet
|
| 1604 |
this condition.
|
| 1605 |
|
| 1606 |
[^30]: In particular, they can report a failure to allocate storage by
|
| 1607 |
throwing an exception of type `bad_alloc`, or a class derived from
|
| 1608 |
+
`bad_alloc` [[bad.alloc]].
|