Consider this class template:
template <typename T1, typename T2, bool B>
class SomeClass { };
Now, I’d like to provide two implementations based on B==true and B==false. That is, I’d like to say something like:
template <ANYTHING, ANYTHING, true> class SomeClass {
// First implementation
};
template <ANYTHING, ANYTHING, false> class SomeClass {
// Second implementation
};
How can this be done in C++(11)?
With partial specialization:
I use a type-wrapper for
bool, but you can also do that withnon-type template parameters:
Sometimes you can compute the value used for partial specialization
with meta-programming in the default argument:
This makes the configuration variable overridable by user choice.
To prevent that, dispatch through inheritance: