I have this simple example to clarify my problem:
struct S;
namespace A{
void f(S&&) {};
namespace B{
struct S{};
}
}
int main(void) {
f(A::B::S());
}
This program is ill-formed since it can't find the name f by argument-dependent lookup.
But cppreference states the following:
Argument-dependent lookup, also known as ADL, or Koenig lookup 1, is the set of rules for looking up the unqualified function names in function-call expressions, including implicit function calls to overloaded operators. These function names are looked up in the namespaces of their arguments in addition to the scopes and namespaces considered by the usual unqualified name lookup.
Per my understanding of the above wording, I see that namespace A is looked up by unqualified lookup, so when ADL searches for the function name f, the namespace A has to be examined in addition to namespace A::B. So why ADL does not search for f in A? Does namespaces A is considered by the usual unqualified name lookup? Am I understand the bold part correctly?
Not quite.
fin your case.A::Bin your case as this function (whose name is still to be looked up) is called with an argument whose type isA::B::S.In conclusion: