namespace N {
class C {};
template<typename X>
char const * found(X && x) {
return "found";
}
template<typename, typename X>
char const * notfound(X && x) {
return "not found";
}
}
This defines a namespace N
with a class C
and two function templates. found
has a single template parameter, which can be deduced from the function argument. notfound
has an additional template parameter which cannot be deduced.
Given following test code (on ideone):
#include <iostream>
int main() {
N::C object;
std::cout
<< found(object) << std::endl
<< notfound<bool>(object) << std::endl // ERROR
<< notfound<bool, N::C>(object) << std::endl; // ERROR
}
I assumed that argument dependent lookup would find both found
and notfound
through the innermost enclosing namespace (which is N
) of the argument type N::C
.
However:
prog.cpp: In function ‘int main()’:
prog.cpp:21:6: error: ‘notfound’ was not declared in this scope
<< notfound<bool>(object) << std::endl
^~~~~~~~
prog.cpp:21:6: note: suggested alternative:
prog.cpp:12:15: note: ‘N::notfound’
char const * notfound(X && x) {
^~~~~~~~
(same error for notfound<bool, N::C>(object)
after commenting out the notfound<bool>(object)
call)
Why is notfound
not found through ADL?
Background: I'm implementing a get
function for some wrapper class, all in all relatively similar to std::get(std::tuple)
. The wrapper class, being an implementation detail, lives in some namespace lib::aspect::part::impl
. I don't want users of the library to specify using lib::aspect::part::impl::get
for obvious reasons.