Topic: Defect Report: examples missing #include <istream> or


Author: gregh@podbridge.com (Greg)
Date: Fri, 6 Oct 2006 18:01:45 GMT
Raw View

On Oct 5, 8:03=A0am, AlbertoBarb...@libero.it (Alberto Ganesh Barbati) wr=
ote:
> Hi Everybody,
>=20
> often on this NG and on comp.lang.c++.moderated, experts (correcly)
> warns non-so-experts that including <iostream> alone does not guarantee
> the inclusion of either <istream> and <ostream> as well.

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 class=
es
are found (as the Standard also requires) in the <istream> and <ostream>
headers. Therefore we have successfully deduced that <iostream> must incl=
ude
<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 th=
e
exact same reasons) when it states: "[Standard Library] C++ headers must
include a C++ header that contains any needed definition." =A717.4.4.1

> 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 woul=
d
be a shame to "wikipedify" the Standard and allow any change to be made j=
ust
as long as enough people (or enough, influential people) believe the chan=
ge
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 t=
he
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 <iostream> must include <istream> and <ostream>. The is=
sue
in #343 is actually which headers must <istream> include.

Greg

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]