D. Susman wrote:
Hi,
What is the difference between using "using std::X" instead of writing
"std::XInstance" every time I use the X instance? Is the latter one
more efficient in the context of compiler dependencies?
The former tells the compiler: "When you're looking for something
called X, please consider the thing called std::X."
The latter tells the compilre: "I specifically want to use std::X here."
The former is generally preferable for functions, because it allows
argument-dependent lookup to be considered. For example, suppose there
is a type "thing" in a namespace "things":
namespace things {
struct thing { ... };
void swap (thing&, thing&);
}
Suppose you later want to swap two things. If you say:
using std::swap;
swap(thing1, thing2);
The compiler has a chance to find things::swap. That's usually a good
thing, since it may use a special thing-specific swapping technique,
e.g. just swapping the things' p_impls.
If instead you say:
std::swap(thing1, thing2);
You will specifically get std::swap, and things::swap will not even be
considered. This is not necessarily wrong, but it is probably sub-optimal.