How do I tell whether I should use
my_type bar;
using some_namespace::foo;
foo(bar);
instead of
some_namespace::foo(bar);
when calling my function foo (that is not within my immediate scope)? Is there a generic “rule” for figuring out whether you should use ADL or not? Which one should I use “by default”?
That is not ADL. In both of your examples,
foois found via normal lookup. An example using ADL would be as follows:Here,
fis not found via normal lookup, but it is found via argument-dependent lookup (because it is in namespacensalongsideA). In any case…Avoid ADL wherever possible.
ADL is beneficial in certain, specific scenarios, for example for operator overloading and for the swappable concept. However, it should be used sparingly, as it leads to bizarre, unexpected behavior in many other cases.