A point from iso C++ n3290 :Argument dependant Name Lookup: section 3.4.2, para 4
When considering an associated namespace, the lookup is the same as the lookup
performed when the associated namespace is used as a qualifier (3.4.3.2) except
that:
— Any using-directives in the associated namespace are ignored.
— Any namespace-scope friend functions or **friend function templates** declared
in associated classes are visible within their respective namespaces even if
they are not visible during an ordinary lookup (11.3).
— All names except those of(possibly overloaded) functions and function
templates are ignored.
Here when compare to earlier 2003 satndard he added the 3rd point . can any one explain how it is possible ...expalin with an example ....(overloaded)..
Andalso he said that in the second point he included the friend function templates(i know noraml calss friend functions) ..can any one explain this thats show's that satatement .
I think the lookup should have always worked like that and is more of a clarification than actual change. I am not sure whether it was added because some other wording was added elsewhere that requires to make this clearer, compilers actually differed in some corner cases or some body questioned what is correct implementation.
Ad point 2. Like you can declare that function f is friend of class c, you can also declare that function template t is friend of class c. The declaration is different, because it explicitly mentions the template arguments, so they felt the need to be explicit both cases apply.
template <typename T> bool f(T);
class c {
friend bool f<c>(c); // only particular instantiation is friend
template <typename T> friend bool f<T>(T); // all instantiations are friends
}
(of course, you can combine this with c
being template itself for unlimited fun).
Ad point 3. The clause means that if looking for function f in a namespace n that contains class f, the class f is not considered (while if you wrote n::f, it would take the class). The "possibly overloaded" does not really have to be there. Functions can always be overloaded and all overloads found across all namespaces will be included in the final overload resolution.
namespace n {
class c { ... };
class e { ... } f;
}
namespace o {
class d { ... };
void f(c &, d &) { ... };
void f(c &, d &, bool) { ... };
}
namespace p {
f(c(), d());
}
Associated namespace of f(c(), d())
are both n
and o
. However n::f
is not a function, but a (possibly functor) instance, so it's not considered (while the old wording allowed considering f
's operator()
). o::f
is overloaded, all overloads are considered (and, after gathering all possible meanings of f, the 3-argument variant is ruled out because only 2 arguments are given).