How can one friend a variadic template function from a template class? Nothing I do does seems to work as the friend function declaration within the class seems to introduce an ambiguous overload for the variadic function
For example this does not work
template <typename... Args>
auto foo(Args&&... args);
template <typename T>
class Something {
public:
template <typename... Args>
friend auto foo(Args&&...);
private:
int foo(int) { return 1; }
};
template <typename... Args>
auto foo(Args&&...) {}
int main() {
foo(Something<int>{});
}
Predeclaring the function in a namespace doesn't work either.. Can this be done? I cannot depend on the function accepting the class itself as a parameter because the function is variadic and needs to accept n parameters which are instantiations of Something
with different types with different reference qualifications
Note that this seems to work with gcc (even without the friend declaration) here https://wandbox.org/permlink/cVa18noVCX189566 and does not work for clang https://wandbox.org/permlink/7MqMO3lgXXp2tAWU
What is the right thing to do here? Who is right - gcc or clang?