20 Library introduction [library]

20.5 Library-wide requirements [requirements]

20.5.1 Library contents and organization [organization]

20.5.1.2 Headers [headers]

Each element of the C++ standard library is declared or defined (as appropriate) in a header.171
The C++ standard library provides the C++ library headers, shown in Table 16.
Table 16 — C++ library headers
<algorithm>
<fstream>
<mutex>
<string>
<any>
<functional>
<new>
<string_­view>
<array>
<future>
<numeric>
<strstream>
<atomic>
<initializer_­list>
<optional>
<syncstream>
<bitset>
<iomanip>
<ostream>
<system_­error>
<charconv>
<ios>
<queue>
<thread>
<chrono>
<iosfwd>
<random>
<tuple>
<codecvt>
<iostream>
<ratio>
<type_­traits>
<compare>
<istream>
<regex>
<typeindex>
<complex>
<iterator>
<scoped_­allocator>
<typeinfo>
<condition_­variable>
<limits>
<set>
<unordered_­map>
<deque>
<list>
<shared_­mutex>
<unordered_­set>
<exception>
<locale>
<sstream>
<utility>
<execution>
<map>
<stack>
<valarray>
<filesystem>
<memory>
<stdexcept>
<variant>
<forward_­list>
<memory_­resource>
<streambuf>
<vector>
The facilities of the C standard library are provided in the additional headers shown in Table 17.172
Table 17 — C++ headers for C library facilities
<cassert>
<cinttypes>
<csignal>
<cstdio>
<cwchar>
<ccomplex>
<ciso646>
<cstdalign>
<cstdlib>
<cwctype>
<cctype>
<climits>
<cstdarg>
<cstring>
<cerrno>
<clocale>
<cstdbool>
<ctgmath>
<cfenv>
<cmath>
<cstddef>
<ctime>
<cfloat>
<csetjmp>
<cstdint>
<cuchar>
Except as noted in [library] through [thread] and [depr], the contents of each header cname is the same as that of the corresponding header name.h as specified in the C standard library.
In the C++ standard library, however, the declarations (except for names which are defined as macros in C) are within namespace scope of the namespace std.
It is unspecified whether these names (including any overloads added in [language.support] through [thread] and [depr]) are first declared within the global namespace scope and are then injected into namespace std by explicit using-declarations.
Names which are defined as macros in C shall be defined as macros in the C++ standard library, even if C grants license for implementation as functions.
[Note
:
The names defined as macros in C include the following: assert, offsetof, setjmp, va_­arg, va_­end, and va_­start.
end note
]
Names that are defined as functions in C shall be defined as functions in the C++ standard library.173
Identifiers that are keywords or operators in C++ shall not be defined as macros in C++ standard library headers.174
[depr.c.headers], C standard library headers, describes the effects of using the name.h (C header) form in a C++ program.175
Annex K of the C standard describes a large number of functions, with associated types and macros, which “promote safer, more secure programming” than many of the traditional C library functions.
The names of the functions have a suffix of _­s; most of them provide the same service as the C library function with the unsuffixed name, but generally take an additional argument whose value is the size of the result array.
If any C++ header is included, it is implementation-defined whether any of these names is declared in the global namespace.
(None of them is declared in namespace std.)
Table 18 lists the Annex K names that may be declared in some header.
These names are also subject to the restrictions of [macro.names].
Table 18 — C standard Annex K names
abort_­handler_­s
mbstowcs_­s
strncat_­s
vswscanf_­s
asctime_­s
memcpy_­s
strncpy_­s
vwprintf_­s
bsearch_­s
memmove_­s
strtok_­s
vwscanf_­s
constraint_­handler_­t
memset_­s
swprintf_­s
wcrtomb_­s
ctime_­s
printf_­s
swscanf_­s
wcscat_­s
errno_­t
qsort_­s
tmpfile_­s
wcscpy_­s
fopen_­s
RSIZE_­MAX
TMP_­MAX_­S
wcsncat_­s
fprintf_­s
rsize_­t
tmpnam_­s
wcsncpy_­s
freopen_­s
scanf_­s
vfprintf_­s
wcsnlen_­s
fscanf_­s
set_­constraint_­handler_­s
vfscanf_­s
wcsrtombs_­s
fwprintf_­s
snprintf_­s
vfwprintf_­s
wcstok_­s
fwscanf_­s
snwprintf_­s
vfwscanf_­s
wcstombs_­s
getenv_­s
sprintf_­s
vprintf_­s
wctomb_­s
gets_­s
sscanf_­s
vscanf_­s
wmemcpy_­s
gmtime_­s
strcat_­s
vsnprintf_­s
wmemmove_­s
ignore_­handler_­s
strcpy_­s
vsnwprintf_­s
wprintf_­s
L_­tmpnam_­s
strerror_­s
vsprintf_­s
wscanf_­s
localtime_­s
strerrorlen_­s
vsscanf_­s
mbsrtowcs_­s
strlen_­s
vswprintf_­s
A header is not necessarily a source file, nor are the sequences delimited by < and > in header names necessarily valid source file names ([cpp.include]).
It is intentional that there is no C++ header for any of these C headers: <stdatomic.h>, <stdnoreturn.h>, <threads.h>.
This disallows the practice, allowed in C, of providing a masking macro in addition to the function prototype.
The only way to achieve equivalent inline behavior in C++ is to provide a definition as an extern inline function.
In particular, including the standard header <iso646.h> or <ciso646> has no effect.
The ".h" headers dump all their names into the global namespace, whereas the newer forms keep their names in namespace std.
Therefore, the newer forms are the preferred forms for all uses except for C++ programs which are intended to be strictly compatible with C.