In article <11**********************@m79g2000cwm.googlegroups .com>,
rd*****@lycos.com says...
Victor Bazarov wrote:
Dilip wrote:
In the text I am reading it says the former is preferred but how does
Koening Lookup assume precedence over ordinary lookup?
The name 'f' is unqualified. So, 3.4.2 governs the lookup. According to
it, other namespaces may be searched. So, they probably are. So, X::f is
*added* to the list of overloaded functions. Then one needs to be picked.
No conversion required for X::f() and that's how it would be preferred.
Impressive, as always. Thanks!
So to be clear I am not really talking about Koening lookup, am I?
Yes, you are.
This is just following lookup rules for unqualifed names, right?
Koenig lookup is one of the lookup rules for unqualified names.
Specifically when you're looking up the unqualified name of a function,
the namespace(s) of its parameter(s) are in the list of places to look.
Was
ADL (I assuming that is what Koening lookup is actually called as)
invented to circumvent lookup problems after C++ templates were
introduced?
If memory serves, ADL was related more closely to the introduction of
namespaces than of templates. While it's convenient for some functions,
it's (mostly) crucial when you use overloaded operators -- the proper
overload of the operator will should normally be in the same namespace
as the type:
namesspace Z {
class X {
};
int f(X const &) {}
std::ostream &operator<<(std::ostream &, X const &) {
};
};
int main() {
Z::X x;
f(x); // ADL finds Z::f()
Z::f(x); // easily done without ADL though.
// not so easy to handle without ADL:
std::cout << x; // no easy way to indicate Z::operator<<
return 0;
}
If so how did the previous snippet function before ADL was introduced?
Without ADL, the function inside of the namespace would never have even
been considered so the one in the global namespace would have been used.
--
Later,
Jerry.
The universe is a figment of its own imagination.