Which is more correct? And Why.
On work I recently run in a discussion how to do a specific template specialization.
This way:
template <typename T, bool someBoolVar = is_polymorphic<T>::value>
struct SomeTemplate { // with empty definition
};
template <typename T>
struct SomeTemplate<T, true> {
...
};
template <typename T>
struct SomeTemplate<T, false> {
...
};
or this way:
template <typename T, bool someBoolVar = is_polymorphic<T>::value>
struct SomeTemplate; // without empty definition -- difference here
template <typename T>
struct SomeTemplate<T, true> {
...
};
template <typename T>
struct SomeTemplate<T, false> {
...
};
Neither. Because both will not compile! Wrong syntax for partial specialization!
This is how partial specialization is done:
Not this:
Now answer to your question assuming you’ll fix the syntax!
In my opinion, the second approach is rational, because
boolcan have ONLY two values, so three versions ofSomeTemplateclass template doesn’t make sense at all, which you’re doing in the first approach.