This can be solve using template specialization
We first declare Programm
as a template taking a bool parameter:
template<bool B>
struct Programm
{
struct SetMatrixUniform()
{
std::cout << "General / Generic Implementation" << std::endl;
}
};
Now we can provide another implementation/specialization for a more concrete case, e.g if B == true
template<>
struct Programm<true>
{
void SetMatrixUniform()
{
std::cout << "Sepcific Implementation For B == true" << std::endl;
}
};
As bool
can only hold two states: true and false, the first implementation will be used if the template is instantiated with false and the second if the template is instantied with true.
This solution however is kind of verbose and requires you two reimplement much of your functionality. If you simply need different behaviour in just some methods, you can also directly compare B
. E.g:
template<bool B>
struct Programm
{
void SetMatrixUniform()
{
if(B == true)
//...
else
//...
}
};