In some of the larger projects or libraries (e.g. Eigen), you can see namespaces like internal
or detail
. I understand what is internal
good for, but what is detail
commonly used for? Is there any common convention for distributing code into namespaces like that (especially in case of libraries with public interface)?
A namespace is a declarative region that provides a scope to the identifiers (the names of types, functions, variables, etc) inside it. Namespaces are used to organize code into logical groups and to prevent name collisions that can occur especially when your code base includes multiple libraries.
In an operating system, an example of namespace is a directory. Each name in a directory uniquely identifies one file or subdirectory. As a rule, names in a namespace cannot have more than one meaning; that is, different meanings cannot share the same name in the same namespace.
Advantages of namespace In one program, namespace can help define different scopes to provide scope to different identifiers declared within them. By using namespace - the same variable names may be reused in a different program.
The using namespace statement just means that in the scope it is present, make all the things under the std namespace available without having to prefix std:: before each of them.
A namespace called detail
is typically used in just the same way as a namespace called internal
. It's for "internal details" that are not visible in the public interface or which, at least, should be ignored by external users.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With