More than once (even on SO) I've seen code like this:
template<typename U, typename... G, typename T = Traits<U>>
struct {
static_assert(sizeof...(G) == 0, "!");
// ...
};
Or this:
template<typename T, typename... G, typename = std::enable_if_t<condition<T>>
void func(T &&t) {
static_assert(sizeof...(G) == 0, "!");
// ....
}
The intent was to avoid users break the rule of the game by doing something like this:
template<typename T, typename = std::enable_if_t<std::is_same<T, int>>
void func(T &&t) {
// ....
}
// ...
func<int&, void>(my_int);
With the guard parameter pack, the defaulted value cannot be overridden.
On the other side, the check on the size avoids pollution of the specializations with useless parameters.
Anyway, because of [temp.res/8], we have that:
The program is ill-formed, no diagnostic required, if:
[...]
- every valid specialization of a variadic template requires an empty template parameter pack, or
[...]
Therefore, are the programs that contain the above mentioned snippets ill-formed or not?
The "trick" results in an ill formed program, no diagnostic required.
The standard states it clearly in the section you quoted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With