
Would it practical to add a rule of thumb to the developer guidelines
library developers should offer a fwd declaration header for their
OP wrote: that library
when possible?
Benoit wrote:
I second this question. In fact, i am wondering whether it would not be even more effective to suggest the separation of each (public) template class into 3 different header files : one containing a forward declaration header, one containing the template class definition and the last one with the definition of its member functions.
I have found in my template programming that it is highly beneficial to separate the template class declaration from the definition of its member functions. This leads to a much more readable set of header files similar to what people are used to reading when definitions are contained within a cpp file. I find the boost code somewhat hard to read because the header files contain all the implementation details that could have been put in a separate definitions hpp. At the very least definitions can be moved to the bottom of the same header file. This does have the drawback, however, that the compiler will complain about cyclic dependencies that it would not otherwise.
That would make it possible to easily separate the compilation of boost classes (or at least their methods) from that of user-defined classes.
No, unfortunately, it wouldn't, because you have to pull in the definitions to use the template class, what you want is precompiled headers. It would, however, allow a header file that makes declarations that include boost references to not have to pull in all the related boost implementation details and slow down the compile time of every compilation unit that depends on it. I consider this benefit secondary to the readability benefit. I third the question, should we make separating template declarations from their definitions a preferred practice? Luke