In my code base, I 'hide' implementation details of heavily templated code in .tcc
files inside a bits
sub-directory, i.e.
// file inc/foo.h:
#ifndef my_foo_h // include guard
#define my_foo_h
namespace my {
/* ... */ // templated code available for user
}
#include "bits/foo.tcc" // includes implementation details
namespace my {
/* ... */ // more templated code using details from foo.tcc
}
#endif
// file inc/bits/foo.tcc:
#ifndef my_foo_tcc // include guard
#define my_foo_tcc
#ifndef my_foo_h
# error foo.tcc must be #included from foo.h
#endif
namespace my { namespace details {
/* ... */ // defails needed in foo.h
} }
#endif
Of course, there must only be one file bits/foo.tcc
in the include path. Otherwise, there will be a clash and (hopefully) a compilation error. This just happened to me with bits/vector.tcc
, which is included from gcc's (4.8) vector
but also my own header (using #include "bits/vector.tcc"
and not #include <bits/vector.h>
).
My question: is this formally a bug of gcc (since it uses a name bits/vector.tcc
which is not protected by the standard) or correct, i.e. even formally my fault? If the latter, what names for header files are guaranteed to be okay to use?
(note I don't want to hear obvious advices of how to avoid this).
Edit The problem is that the header file vector
provided by the standard library (shipped by the compiler) has a preprocessor directive #include <bits/vector.tcc>
which causes the preprocessor to load my file rather than that provided with the standard library.