There is a claim in Which headers in the C++ standard library are guaranteed to include another header?:
The C++ standard library headers may include each other in unspecified ways, so programmers generally shouldn't depend on one header including another. [...]
In practice this tends to be the case. For example, <iostream>
may include <string>
, in other cases you need to include <string>
explicitly. However, I can't seem to find where in N4140 this is the case. I've looked in:
- §2.9 [lex.header]
- §17.6.1.2 [headers]
- §17.6.2.2 [using.headers]
- §17.6.4.4 [alt.headers]
- §17.6.5.2 [res.on.headers]
The closest I can find is from [using.headers]:
2 A translation unit may include library headers in any order (Clause 2). Each may be included more than once, with no effect different from being included exactly once, except that the effect of including either
<cassert>
or<assert.h>
depends each time on the lexically current definition of NDEBUG.178
But this seems to apply to C++ programs, not the standard library:
[using.overview]/1 This section describes how a C++ program gains access to the facilities of the C++ standard library. [...]
As well as [res.on.headers]:
1 A C++ header may include other C++ headers. A C++ header shall provide the declarations and definitions that appear in its synopsis. A C++ header shown in its synopsis as including other C++ headers shall provide the declarations and definitions that appear in the synopses of those other headers.
I think the key is the first sentence, but it doesn't explicitly say that it's unspecified behavior. Does it state anywhere that this is unspecified behavior or is it simply implied?