Re: [boost] New libraries should provide forward declarations? (Benoit))

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.
This is not exactly true. I already use such an approach in my own developments. The idea is to use concepts to make sure that the right member functions are called inside a cpp file and therefore will be compiled and usable everywhere.That would mean pulling in all related implementation details... But only for one compilation unit (created with that purpose in mind). Other compilation units would only have access to template class definitions. For that matter, i personally use the .h extension for template class definitions and .hpp for template class method definitions (but that's only an example of what could be done).
Note that i agree that it would also bring a readability benefit to the source code.
Benoît
This sounds exactly like what I am trying to do, I already split the declarations into .h files and the definitions into .hpp. Can you give a brief example of using a single .cpp file for compilation? Is this done like MSVC stdafx files? Thanks, Robert ________________________________

on Fri Aug 22 2008, rtsweng-sw-AT-yahoo.com wrote:
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.
This is not exactly true. I already use such an approach in my own developments. The idea is to use concepts to make sure that the right member functions are called inside a cpp file and therefore will be compiled and usable everywhere.That would mean pulling in all related implementation details... But only for one compilation unit (created with that purpose in mind). Other compilation units would only have access to template class definitions. For that matter, i personally use the .h extension for template class definitions and .hpp for template class method definitions (but that's only an example of what could be done).
Note that i agree that it would also bring a readability benefit to the source code.
Benoît
This sounds exactly like what I am trying to do, I already split the declarations into .h files and the definitions into .hpp. Can you give a brief example of using a single .cpp file for compilation? Is this done like MSVC stdafx files?
For what it's worth, the Boost convention is that all C++ filenames end in "pp". Those who follow the convention tend to use ".ipp" files for implementation headers. -- Dave Abrahams BoostPro Computing http://www.boostpro.com

On Fri, 22 Aug 2008, David Abrahams wrote:
This sounds exactly like what I am trying to do, I already split the declarations into .h files and the definitions into .hpp. Can you give a brief example of using a single .cpp file for compilation? Is this done like MSVC stdafx files?
For what it's worth, the Boost convention is that all C++ filenames end in "pp". Those who follow the convention tend to use ".ipp" files for implementation headers.
By my count, boost ships 105 .ipp files and 274 _impl.hpp files... - Daniel

This sounds exactly like what I am trying to do, I already split the declarations into .h files and the definitions into .hpp. Can you give a brief example of using a single .cpp file for compilation? Is this done like MSVC stdafx files?
Although i use visual studio, I don't know how stdafx files work. I get rid of them (when autogenerated) as soon as possible ! Now considering your question on how to compile template class instantiations, the first idea is to use the auto-compilation command (for a lack of a better expression). Suppose you have two files myclass.h and myclass.hpp that define a class template myclass requiring one argument. What you want is to use myclass<int> somewhere (or everywhere, it doesn't matter) in your project. You may create myclass.cpp as follows : #include "myclass.hpp" // Obviously, myclass.hpp includes myclass.h template myclass<int>; In most cases, this is enough. This command instantiates all non-template member functions of myclass for the particular instantiation myclass<int>. Note that, if you do have template methods that are called by non-template methods, you should be fine. But of course, this is only the simple case. Concepts are pretty handy when it comes to dealing with *those* not-so-simple cases. Let's define a concept for what myclass should do (in concept_myclass.hpp for example) template<typename verify_class> class concept_myclass { void constraints( verify_class& verify ) { compute_type i = verify.compute( 3, 2 ); double d = verify.get_square_root( i ); // ... and so forth } typedef typename verify_class::compute_type compute_type; }; This is a fairly simple example, but you get the idea. Now you can create a cpp file to "compile" your hpp file : #include "myclass.hpp" #include "concept_myclass.hpp" template concept_myclass<myclass<int> >; Now everything should work the way you wish it would (i hope !). At some point i'll try and make this really compatible with the concept check library, but i haven't had time to look into that so far. I personnally use a configuration file which contains typedefs for pretty much all template class instantiations. I believe It reduces the number of possible errors when you decide to change the template arguments. Using this, the previous cpp file becomes : #include "myclass.hpp" #include "concept_myclass.hpp" #include "config.hpp" template concept_myclass<config::myclass>; That's all !!! Benoît Casoetto David : i take good note of boost recommandations on file naming, thanks !
participants (4)
-
Benoit
-
David Abrahams
-
dherring@ll.mit.edu
-
rtsweng-sw@yahoo.com