I use a template parameter to determine if a certain behavior must be done or not. But this code generate a warning on VS2008 : Warning 26 warning C4127: conditional expression is constant
Here an exemple of the code :
template <class param, bool param2=true>
class superclass1
{
public:
int foo()
{
if(param2)
doSomthingMore();
return 1;
}
};
Is there a way to tranform the code to remove the warning and get the same features?
This is done via partial specialization. The crudest version looks like this:
A more sophisticated approach might declare a member template function and only specialize that. Here’s a solution with auxiliary tag classes: