Name lookup of specialized template function looks in a namespace that is not opened, and the name lookup is dependent on the types of the parameters in the template parameter pack.
It also only happens when I specialize the function, not when I just overload it in the namespace.
All C++ compilers seems to agree on this, so I wonder why this is? An intuitive understanding of it would be to only look-up in open namespaces. Is this a bug that all compilers have, or what am I missing?
This code - where I use a parameter declaret in the namespace 'space' - does not compile. If I do not use a parameter declared in 'space' it does compile. https://godbolt.org/z/2-nRYW
#include <memory>
#include <functional>
using namespace std;
template< typename T, class Alloc, typename... Args >
unique_ptr<T> the_funk(Alloc alloc, Args&& ... args) {
throw "";
}
namespace space {
template< typename T >
class ATestTypeB { int mA; };
template< typename T, template< typename > class Alloc, typename X, typename... Args >
unique_ptr<T, function<void()> > the_funk(Alloc<X> alloc, Args&& ... args) {
throw "";
}
}
int main() {
class AnotherClass { int mA; };
shared_ptr<int> a;
space::ATestTypeB<int> b;
int c;
std::unique_ptr<AnotherClass> obja = the_funk<AnotherClass>(a, b); // <-- Does not compile. Tries space::the_funk
std::unique_ptr<AnotherClass> objb = the_funk<AnotherClass>(a, c); // <-- Compiles. Uses ::the_funk
}
As Sander De Dycker point out that is just how Argument Dependent Lookup works.