Suppose I have a template which takes 3 template parameter.
I want the third template parameter to be taken by some another template say “CHECK” that may return any integer in case as CHECK fails else “1”. In case of “1” class X is specialized.
As shown in following code.
How can I achieved it, i.e. how can I force default template argument to be always used(objective is to make it mandatory not default).If such design is required what should be done?
In short “I want prevent users from supplying that third parameter”.
template<typename T, typename D , int = CHECK<T, D>::IS_TRUE >
class X
{
public :
X()
{
using namespace std;
cout << "Inside General Implementation " << endl;
}
};
template<typename T, typename D>
class X<T, D, 1>
{
public :
X()
{
using namespace std;
cout << "Inside SPECIAL Implementation " << endl;
}
//Specialized Implementaion
};
int main(int argc, char* argv[]) try
{
X<MyWiget, YourWiget > xObj ; //CHECK used desired behaviour
X<MyWiget, YourWiget, 1 > xObj ; //CHECK not used specialized behaviour
X<MyWiget, YourWiget, 2 > xObj ; //CHECK not used i.e. default template argument not used
}
catch(...)
{
//should not land here
using namespace std;
cout << " Problems in exception handling in code";
}
IIUC, you want prevent users from supplying that third parameter.
Rename your class
XtoX_impland supply a newX, with less parameters: