C++ provides the using keyword for use in declarations and directives relating to namespaces. This powerful capability can simplify and reduce the verbosity of code, but it can also lead to reliability and maintainability challenges when the source of non-local names is not obvious.
Using-declarations are of the form using N::Class; or using N::function;. These inject a name from a different namespace into the current namespace, where it may be used without qualification.
Using-directives are of the form using namespace N;. These inject all the names in the different namespace into the current namespace.
Coding convention 4-13 bans using using-declarations and using-directives in header files. (It is incorrect about using-directives requiring qualification of names from the different namespace; this may be due to an incorrect analogy with the Python import statement.)
The LSST convention for .cc source files that are not included in header files is:
- Using-declarations are acceptable and appropriate for use when the class or function is to be referenced repeatedly.
- Using-directives are to be avoided except where N is std. This convention ensures that unfamiliar names will be properly namespace-qualified at least once in the file.
...