astar-algorithm-cpp icon indicating copy to clipboard operation
astar-algorithm-cpp copied to clipboard

C++ headers shouldn't do `using namespace std;`

Open sylveon opened this issue 4 years ago • 0 comments

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):

https://github.com/justinhj/astar-algorithm-cpp/blob/9b2597e10110d1b8c6a297d52fa06500182d89b5/cpp/stlastar.h#L40

The source .cpp files, however, can keep doing using namespace std since it won't affect any other files.

sylveon avatar Apr 25 '21 20:04 sylveon