namespace X
{
    namespace Y
    {
        template <typename R, typename ...T>
        R foo(T&&... args)
        {
            R r(args...);
            return r;
        }
    }
}

class A
{
    template <typename R, typename ...T>
    friend R X::Y::foo(T&&... args);
    A(int x, int y){}
};

int main()
{
    X::Y::foo<A>(1, 2);
}