I have this code
template<int N, bool C = true>
struct A;
template<int N>
struct A<N, !(N % 5)> {
/* ... */
};
// should work
A<25> a;
That is, for numbers N
that are divisible by 5
, the compiler should use the partial specialization. But the compiler won't accept that partial specialization, because the Standard requires it to reject such code where a non-type argument of a partial specialization references a parameter and is not simply a parameter (like, A<N, N>
would be valid). But what is the reason of doing so?
Note that I can simply change my code to a more wordy example and it is valid
template<bool> struct wrap;
template<int N, typename = wrap<true> >
struct A;
template<int N>
struct A<N, wrap<!(N % 5)> > {
/* ... */
};
// should work
A<25> a;
This is fine because it's not a non-type parameter anymore. But what is the reason the spec forbids the more straightforward partial specialization?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…