There seem to be different views on using \'using\' with respect to the std namespace.
Some say use \' using namespace std
\', other say don\'t but rathe
You should never be using namespace std
at namespace scope in a header. Also, I suppose most programmers will wonder when they see vector
or string
without std::
, so I think not using namespace std
is better. Therefor I argue for never be using namespace std
at all.
If you feel like you must, add local using declarations like using std::vector
. But ask yourself: What's this worth? A line of code is written once (maybe twice), but it's read ten, hundred or thousand times. The saved typing effort be adding a using declaration or directive is marginal compared to the effort of reading the code.
With that in mind, in a project ten years ago we decided to explicitly qualify all identifiers with their full namespace names. What seemed awkward at first became routine within two weeks. Now, in all projects of that whole company nobody is using using directives or declarations anymore. (With one exception, see below.) Looking at the code (several MLoC) after ten years, I feel like we made the right decision.
I've found that usually, those who oppose banning using
usually haven't tried it for one project. Those who have tried, often find it better than using directives/declarations after a very short time.
Note: The only exception is using std::swap
which is necessary (especially in generic code) to pick up overloads of swap()
that cannot be put into the std
namespace (because we aren't allowed to put put overloads of std
functions into this namespace).