Quote:
Using a using declaration or using directive in any scope can lead to bugs in your program.
Writing code can lead to bugs in your program (thus the larger and more complex the software, the more bugs it probably has). So, that using a using declaration or using directive in any scope can lead to bugs is of no consequence. What is important is whether the use is appropriate, e.g., a using declaration when overloading a member function of a base class in a derived class is undeniably a Good Thing.
Quote:
Placing std:: in front of names from the std namespace will remove that specific possibility (however remote).
I agree that always fully qualifying names from the std namespace will avoid such bugs. On the other hand, as you say such bugs with respect to using declarations and using directives are a remote possibility that is especially unlikely when used in a limited scope such that the potential error is more easily spotted and corrected.
Quote:
The C++ Coding Standards advice should be considered, but it applies to other namespaces much more than it does to the std namespace.
What is your reasoning? It seems to me that chances of name conflicts from a namespace other than the std namespace may be even greater in view that library designers are more likely to avoid names that may conflict with those from the std namespace.
Quote:
While I wouldn't tell somebody not to use a using directive or declaration for the std namespace in a source file or in function scope, I don't see how you can advise somebody that they should be using it.
Personally, I would rather give a code example with names fully qualified than use a using declaration or directive for brevity's sake and then have to explain the appropriate use of the using declaration or directive (thus removing my gain of brevity, heheh).
However, I can see how one would advise someone else to use using declaration and directives properly: they are useful to reduce unnecessary typing, and in that sense, reduce code clutter. Daved, you recommended Accelerated C++, and Koenig and Moo introduce using declarations with that in mind in chapter 2.5. Admittedly they probably also had the ulterior motive of reducing code length in the book, but they do make it clear that a possible name conflict can occur, e.g., if the reader goes on to define something named cout.
Quote:
The using declaration was intended to make your life easier in some cases, but that doesn't necessarily include the std namespace.
You might have forgotten that using std::swap is useful when implementing a swap as it would use a free function swap (likely to be more optimised than the generic swap) if it exists, or std::swap if such a swap function does not exist. Okay, that is probably nitpicking :p, but yeah, the usefulness of using declarations does extend to the std namespace, even if one prefers to prefix std:: under normal circumstances.
Quote:
If readability is solely behind the "using" argument, then I would argue that typing fully-qualified names also explicitly documents your intention to use a name from that class/namespace
A using declaration would have the same effect, especially in a limited scope.
Quote:
In any case, if you feel comfortable with the syntax enough to use it all the time in your own code, then there's certainly no argument to be doing otherwise. On the other hand, if you don't feel comfortable with it, then don't use it, that's fine aswell.
I agree.