Not all requirements need to be explicitly stated. For example, we can
readily deduce that <iostream> must include <istream> and <ostream> from the
requirement that <iostream> must declare the global stream objects:
std::cout, std::cin and friends.
First, we know that in order for <iostream> to be able to declare the set of
global stream objects, the <iostream> header itself must be well-formed.
After all, an ill-formed <iostream> header has no chance of declaring
anything. And in order for <iostream> to be well-formed, it must include the
class definitions for the std::istream and std::ostream objects it is
obligated to declare. Furthermore, the definitions for these stream classes
are found (as the Standard also requires) in the <istream> and <ostream>
headers. Therefore we have successfully deduced that <iostream> must include
<istream> and <ostream> in order for it to declare the objects that the
Standards requires that it declare. So it should not come as a surprise,
that <iostream> always does include those two headers.
Nor are we alone in following this line of reasoning; the Standard itself
reaches the same logical conclusion that we just did (and no doubt for the
exact same reasons) when it states: "[Standard Library] C++ headers must
include a C++ header that contains any needed definition." 18.104.22.168
>> What about the
>> C++ standard? It seems that there are five different examples that are
>> lacking proper #includes. Those are:
>> We can't fix all the books out there promoting this incorrectness, but
>> at least the standard should be correct, shouldn't it?
The existing examples in the Standard are correct as written. And it would
be a shame to "wikipedify" the Standard and allow any change to be made just
as long as enough people (or enough, influential people) believe the change
should be made. In a Standard wikipedified in this manner, not even the
logic of its own requirements, the supporting evidence of every C++
implementation and just plain common sense would be allowed to stand in the
way of the force of popular opinion.
It may also be worth noting that Standard Library Issue #343 which deals
with ambiguous header dependencies in the C++ Standard, implicitly
acknowledges that< must include< and<. The issue
in #343 is actually which headers must< include.
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:email@example.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.yqcomputer.com/ ]