I want to consider functions in the namespace of non-type template parameters during lookup in a function call.
For example:
template<auto& N>
struct test_nontype {
int call() {
return f(*this); // error: 'f' was not declared in this scope
}
};
template<typename T>
struct test_type {
int call() {
return f(*this); // ok, f is found in ns via ADL
}
};
namespace ns {
static struct type_in_ns {} value;
int f(test_nontype<value>) {
return 3;
}
int f(test_type<type_in_ns&>) {
return -3;
}
}
int main() {
int x = test_type<ns::type_in_ns&>{}.call();
return x + test_nontype<ns::value>{}.call();
}
With types it works fine, but the last line fails to compile since int ns::f(test_nontype<ns::value>)
can't be found.
I would rather not add a parameter template<auto& N, typename = decltype(N)> struct test_nontype {
if there are alternatives, since adding a template arguments and that just makes the interface more confusing (I would have to add a comment explaining it's for ADL, but the IDE still suggests adding a type name, and it also adds more noise to compile errors)
What other work arounds are there?