user1641854 user1641854 - 27 days ago 20
C++ Question

Koenig lookup for arguments

Is idea of Koenig lookup for arguments a bad thing?

With ADL we have:

namespace foo
{
struct bar {};
void baz(bar);
}

baz(foo::bar());


And why we don't have something like:

namespace foo
{
struct bar {};
void baz(bar);
} // namespace foo

foo::baz(bar());

Answer

Focusing on the non-duplicate part, why not foo::baz(bar());? The simple reason is that in C++, the parse tree is always processed bottom to top. Name lookup of a function name depends on the function arguments, not the other way around, just like overload resolution depends on the argument types and not the return type.