In C++ we can omit namespace qualification in case of using function that takes, as its first argument, object of type declared in the same namespace as our function. However, I've noticed that this doesn't work with templated functions (like std::get). I wrote simple example to confirm that this is really related to templates:
namespace ns {
struct S {};
void sFoo(const S&) {}
template<typename T> void sBar(const S&) {}
}
void foo()
{
ns::S s;
sFoo(s); // ok
sBar<int>(s); // error: ‘sBar’ was not declared in this scope
ns::sBar<int>(s); // ok
}
I tried explicit instantiation, but it didn't change anything (even if it would, it would be worse option than just using using).
So why exacly can't I call templated function without specifying its namespace (and assuming neither using nor using namespace directives)?