Principia icon indicating copy to clipboard operation
Principia copied to clipboard

Use internal namespaces in header files, not unnamed namespaces.

Open eggrobin opened this issue 10 years ago • 1 comments

Many instances.

eggrobin avatar Aug 01 '15 12:08 eggrobin

The solution of #96 proved unsatisfactory, since we would end up relying on using-declarations made in principia from other files, which made things dependent on inclusion order and caused conficts.

using-declarations that are not part of the API should therefore be made in internal namespaces; any declarations made in that internal namespace can use the usings, and can be exported outside (using using).

This also allows referring to internal types in the declarations and definitions without having to use internal::.

In order to avoid cross-contamination of internal namespaces, they should be named per header-body-test unit.

Example:

// in file foo.hpp, foo_body.hpp, or foo_test.cpp
namespace principia {
namespace project {
namespace internal_foo {

using other_project::SomeType;

SomeType Baz(SomeType baz);

class Foo {
 public:
  SomeType Bar();
};

}  // namespace internal_foo

// In file foo.hpp
using internal_foo::Baz;
using internal_foo::Foo;

}  // namespace project
}  // namespace principia

using-declarations in the hpp should not be repeated in the _body.hpp nor the _test.cpp; using-declarations in the _body.hpp should not be repeated in the _test.cpp;

Files that do not have non-API using-declarations nor internal declarations need not follow this scheme.

eggrobin avatar Jun 10 '16 23:06 eggrobin