C++ Logo

std-proposals

Advanced search

Variadic Friends

From: Jody Hagins <coachhagins_at_[hidden]>
Date: Fri, 31 Jan 2020 13:44:48 -0500
I would like to get feedback on adding a new clause to 17.5.3:4 [temp.variadic] such that the following example would make all classes in the expanded pack friends.

template <typename ... Ts> class Foo
{
    friend Ts...;
};

If the pack is empty, there are no friend declarations. Otherwise, it would be as-if there were one friend declaration for each type in the Ts parameter pack. For example,

// As-if instantiation for Foo<>
template <> class Foo<> {
};

// As-if instantiation for Foo<A>
template <> class Foo<A> {
    friend A;
};

// As-if instantiation for Foo<A, B, C>
template <> class Foo<A, B, C> {
    friend A;
    friend B;
    friend C;
};

While this does not fit the more traditional patterns for parameter pack expansion, it is not too different from variadic-using statements.

I would have thought that this would have already come up, but I can't seem to find anything via google searches, nor a search of this group history. In addition to feedback on this, I would also appreciate any input on how to improve searches for such things.

Thanks!


Received on 2020-01-31 12:47:28