Using namespaces in headers is considered bad practice because they unconditionally and irreversibly pollute the global namespace of every consumer.
This leads to conflicts especially since the std namespace uses a lot of general terms that someone might want to use elsewhere, for example function and copy. The user in https://github.com/microsoft/STL/issues/1881 was having issues with a library conflicting with the standard library specifically because of this line (the library is in the endian namespace while C++20 has an std::endian enum now):
Using namespaces in headers is considered bad practice because they unconditionally and irreversibly pollute the global namespace of every consumer.
This leads to conflicts especially since the
std
namespace uses a lot of general terms that someone might want to use elsewhere, for examplefunction
andcopy
. The user in https://github.com/microsoft/STL/issues/1881 was having issues with a library conflicting with the standard library specifically because of this line (the library is in theendian
namespace while C++20 has anstd::endian
enum now):https://github.com/justinhj/astar-algorithm-cpp/blob/9b2597e10110d1b8c6a297d52fa06500182d89b5/cpp/stlastar.h#L40
The source
.cpp
files, however, can keep doingusing namespace std
since it won't affect any other files.