What is the best / cleanest way to use namespaces in packaged code?
eg. libraries like boost seem to have very organized namespace management, using some methods that eliminate name ambiguity. However, the important thing is that there will not be much code, for example
typedef namespace1::namespace2::sth_else::a_class<namespace3::namespace4::b_class> type;
usually there are not many cross-names, which indicates a good architecture, but also good namespace management. The question is, what is good namespace management?
Say we have a file structure:
component1/... (depends on reusable_if) component2/... (depends directly on reusable_if and on component 1) reusable/ reusable/some_part/ reusable/some_part/... reusable/some_other_part/ reusable/some_other_part/... reusable/SthThatUsesBothReusableParts.h (implements reusable_if/ISth.h) reusable/SthThatUsesBothReusableParts.cpp (implements reusable_if/ISth.h) reusable_if/ reusable_if/ISth.h (pure abstract class) reusable_if/ISthElse.h (pure abstract class) main.cpp (eg instantiates SthThatUsesBothReusableParts and passes to component1/2)
The reason the reusable_if / folder exists is because both component1 and component2 want to reuse the same interfaces (therefore, none of them own "interfaces" exclusively). In addition, it is assumed that the project is really very large and requires its own namespaces for classes in each of the folders.
How would you apply namespaces in such a project? Let's say I declare all classes in a reusable / namespace ::reusable . Should I put interfaces from reusable_if in the ::reusable namespace or in ::reusable_if ? Or maybe there is none, since it is used by components 1 and component2?
What about namespaces in components 1 and component2? Anything to remember? What about the using keyword? Say I decided to add this namespace ::reusable_if . Can I put using reusable_if in the header files in components 1 and 2, provided that using ... is placed in the namespace ::component1 and ::component2 ?
I am open to any suggestions, as well as those that are not necessarily related to the above example.