Topic: Including facilities


Author: Michiel Salters<Michiel.Salters@cmg.nl>
Date: Sat, 17 Nov 2001 00:26:05 GMT
Raw View
In article <2eb1bafb.0111142224.3d82b491@posting.google.com>,
=?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?= says...
>
>Hello.
>
>I would like to propose that the mechanism of including standard
>facilities were improved to promote consistency and to avoid
>confusion, especially among new users of the language. I am
>particularly talking about requiring that each and every facility used
>in a translation unit has its corresponding "header" explicitly
>included.

There's another thread about this very subject, in which many
have pointed out that C++ explicitly allows std headers to include
other std headers. This was an intentional diference from C, and I
don't expect it to be turned back.

I'm also not aware of the problem you mention with junior programmers;
they tend to add headers to get their program to compile. That's it.

Regards,
Michiel Salters

--
Michiel Salters
Consultant Technical Software Engineering
CMG Trade, Transport & Industry
Michiel.Salters@cmg.nl

---
[ 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.research.att.com/~austern/csc/faq.html                ]





Author: zunino@unu.edu (=?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?=)
Date: Thu, 15 Nov 2001 16:57:42 GMT
Raw View
Hello.

I would like to propose that the mechanism of including standard
facilities were improved to promote consistency and to avoid
confusion, especially among new users of the language. I am
particularly talking about requiring that each and every facility used
in a translation unit has its corresponding "header" explicitly
included. For instance, I find it annoying and potentially confusing
that the following program compiles in my implementation:

#include <iostream>
#include <set>
#include <vector>
#include <string>

int main()
{
  using std::cout;
  using std::set;
  using std::vector;
  using std::string;

  set<string> phrases;
  phrases.insert("the sky is blue");
  phrases.insert("something in the way she moves");
  phrases.insert("foo went to the bar");

  vector<string> phrasesCopy(3);

  std::copy(phrases.begin(), phrases.end(), phrasesCopy.begin());

  return 0;
}

while the following, does not:

#include <iostream>
#include <string>

int main()
{
  using std::cout;
  using std::string;

  string phrase = "foo went to the bar";

  string phraseCopy;
  phraseCopy.reserve(32);

  std::copy(phrase.begin(), phrase.end(), phraseCopy.begin());

  return 0;
}

The compiler diagnose for the second is:

Error E2316 test2.cpp 20: 'copy' is not a member of 'std' in function
main()

which I would also expect to be the case for the first program, since
in none of them I am #including the <algorithm> standard header, where
the std::copy facility is provided.

I am not sure about how difficult or if it would even be reasonable
for the Language Standards to enforce such requirements, but I am sure
the present situation can be a source of confusion and even
maintainability problems.

One could even consider adopting a different, more modern way of
handling the inclusion of facilities. Maybe a keyword like "import" or
maybe even no include/import at all, with the using declarations being
sufficient.

I apologize in advance if my comments and suggestions are too
superficial and not in line with the usual highly detailed level of
the discussions here, but I just thought I should mention it.

And, by the way, while we are at it, I would also like to mention one
old pet peeve of mine regarding using declarations: why is it not
possible for a list of symbols to be provided as opposed to just one?
Allowing that would make it much more convenient, without breaking any
code:

#include <iostream>
#include <string>

int main()
{
  using std::cin, std::cout, std::string;

  // ...

  return 0;
}

Regards,

--
Ney Andr    de Mello Zunino

---
[ 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.research.att.com/~austern/csc/faq.html                ]