Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visibility rules for mixin inheritance with variadic template

Consider I inherit from a variadic template the entire arguments list. How are the arguments inherited?

// snippet
template<typename... R>
class foo
    : public R... {
public: 
};
// ....
using foo_inst = foo<bar_1, bar_2>;

I tried it, and it seems all R's are inherited public (not just the first one). Is this defined behavior?

I tried it with gcc and msvc (thanks to jaggedSpire also with clang), all with same results. The compilers not even mentioned any warnings. You can see a running example here.

like image 906
user1810087 Avatar asked Sep 28 '22 08:09

user1810087


1 Answers

Yes, this is the defined behaviour. Quoting from 14.5.3[temp.variadic]\4

A pack expansion consists of a pattern and an ellipsis, the instantiation of which produces zero or more instantiations of the pattern in a list (described below). The form of the pattern depends on the context in which the expansion occurs. Pack expansions can occur in the following contexts:

The relevant context from that list is:

— In a base-specifier-list (Clause 10 ); the pattern is a base-specifier.

Thus, in the parameter pack expansion class foo : public R..., the pattern is the base-specifier public R, making the pack composed of types T1, T2, ... , Tn expand to public T1, public T2, ... , public Tn. (Ellipsis in the previous sentence are used in the mathematical sequence-specifying sense.)

like image 89
Pradhan Avatar answered Nov 15 '22 09:11

Pradhan