justinhj / astar-algorithm-cpp

Implementations of the A* algorithm in C++
MIT License
437 stars 192 forks source link

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

Closed sylveon closed 2 years ago

sylveon commented 3 years ago

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.

justinhj commented 2 years ago

Thanks for pointing this out, have fixed.