How to declare a variadic template function as a friend?
Asked Answered
J

1

11

How to declare a variadic template function as a friend?

For example as follows:

template<class T>
class A
{
    friend ??? MakeA ??? ; // What should be placed here ???

    A(T)
    {}
};

template<class T, class... Args>
A<T> MakeA(Args&&... args)
{
    T t(std::forward<Args>(args));

    return A(t);
}
Jedda answered 15/2, 2014 at 3:46 Comment(0)
R
11

It's quite straightforward. It's simply a template declaration with the added friend specifier:

template<class T>
class A
{
    template<class T1, class... Args>
    friend A<T1> MakeA(Args&&... args);

    A(T) { }
};
Rodi answered 15/2, 2014 at 3:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.