Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Namespaces and C++ library

Is a namespace contained in a library or a library is contained in a namespace?
How many namespaces are there in the C++ standard library ?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

They are orthogonal. A library can use multiple namespaces and a namespace can be split between multiple libraries. However it is a good practice to scope the contents of a library to a (usually single) namespace (+ namespaces nested therein) specific to that library to avoid name clash between multiple libraries and for clarity.

The standard library uses (aside from the global namespace scope) only the std namespace (+ nested namespaces), although namespaces named std followed by any number of digits and the namespace posix are also reserved to the standard library for future standardization. The standard library also has multiple nested namespaces inside std, e.g. std::filesystem and std::ranges, and certain names are reserved for it in the global namespace scope.

The standard library also explicitly allows user code (including user libraries) to add certain declarations (in particular partial specializations of some classes) to the std namespace. So std is not always completely restricted to the standard library either.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading