[OpenWalnut-Dev] Header dependencies

Mathias Goldau math at informatik.uni-leipzig.de
Fri Jan 28 13:22:49 CET 2011


Hi,

I am not the first who observed that our compile time is a bit slow. Up to a
certain level we can improve if we use forward declarations.

Q: When to use forward declarations?
A: When ever you can, and it does make sense.

Q: When does it make sense?
A: Only when the include is referencing our OW code, hence it does not refer
to third party or to the std library includes.

Q: Can I also forward templates?
A: Yes: but if the template changes later, you might change all those forward
declarations too. I not recommend it without any reason, decide at your own if
your really need it. An example is e.g.:
template< class > class WModuleInputData;

Q: Can I forward typedefs?
A: Yes: class A;typedef A B; But be aware that if the typedef is changing you
must change all forwarded typedefs which may not always be obviously, e.g.
when both typedef versions using available types with the same interface.

Q: Can I forward types inside namespaces?
A: Yes: just open the namespace and place your forward declaration there, but
I would not recommend this, since we are try to remove some namespaces anyway
(e.g. wmath).

Q: What cannot be forwarded?
A: Base classes used for class inheritance declaration ala:
class A : public B {...}, all std templates, e.g. list, vector,... and all
members.

Q: What can be forwarded?
A: If you have boost::shared_ptr< SomeThing >, than you typically need just to
forward SomeThing. Even if this is a member declaring expression. Parameters
of member functions and return types.

You may consider further the PIMPL idiom using with a
"const auto_ptr< IMPL > m_pimpl; See Scott Meyers item 31. There also
objections beside beautiful code on that, but for further details ask
Sebastian aka ebaum.

You may investigate with our new script tools/sourceDeps the most used header
files.

math

-- 
Institut für Informatik
Universität Leipzig
Johannisgasse 26, 04103 Leipzig
Phone: +493419732283


More information about the OpenWalnut-Dev mailing list