
On Nov 20, 2006, at 7:48 AM, John Maddock wrote:
I think the problem here is that it's tricky to ensure that you have all the necessary headers included: different implementations may or may not flag up an error depending which headers you've included, so including <iostream> is a sort of "belt-and-braces" approach.
The local fix for this is to write a library's cpp file that get compiled into the library.h, whose first line is #include "filename.h". This ensures that all the right headers get pulled in properly. In fact, the standard practice is to always include the headers in *reverse* order of dependency. The same works for the test driver: there is one test file dedicated simply to make sure that #include "filename.h" works without including anything else. It's a bit of a discipline and one must make sure that all code template has been instantiated, so it (like anything else) is not foolproof. You also need a notion of physical dependency and hierarchy levels. For this, I refer to John Lakos' book (whose second edition is in the writing).
As an aside, I've always wanted a sort of "conceptual" std lib implementation, that included in each header nothing except what absolutely has to be there. Just the declarations would do, so we could do compile-time tests against it to verify inclusion of the right headers: the only tricky bit is getting the compile time constants correct so that it can still compile meta code. Any volunteers? :->
John: I'm not sure I understand the only tricky bit. Can you pls elaborate? -- Hervé Brönnimann hervebronnimann@mac.com