I'm having trouble understanding rules that depend on argument dependent (Koenig).
Consider the code below:
#include <iostream> using namespace std; namespace adl { struct Test { }; void foo1(Test const &) { cout << "ADL used (foo1)" << endl; } void foo2(Test const &) { cout << "ADL used (foo2)" << endl; } void foo3(Test const &) { cout << "ADL used (foo3)" << endl; } } struct foo1 { foo1() { } template<class T> foo1(T const &) { cout << "ADL not used (foo1)" << endl; } template<class T> void operator()(T const &) const { cout << "ADL not used (foo3)" << endl; } }; template<class T> void foo2(T const &) { cout << "ADL not used (foo2)" << endl; } int main() { adl::Test t; foo1 foo3; (foo1(t)); (foo2(t)); (foo3(t)); }
His conclusion:
ADL is not used ( foo1 )
Used by ADL ( foo2 )
ADL is not used ( foo3 )
I expected all of them to use ADL, but I was surprised that only a few of them did.
What are (potentially burning, I know) the details behind ADL rules?
I understand the concept quite well, but the details are what I came across.
What search areas are viewed when they are being performed, and when they are not being searched?
Is it even possible to determine if ADL is being used without looking at all the #include 'files before a given line of code? I expected functors and functions to behave the same in terms of [not] masking ADL, but apparently they do not.
Is there a way to force ADL in cases when it does not run automatically (for example, above), and you do not know the class namespaces (for example, in a template)?
source share