I have a template class, inside which i have a normal function. But i want to enable this normal function only for certain instantiations of a template class. I looked at boost::enable_if and it doesn’t suit my need exactly / may be i am not able to use it for my need.
typedef boost::mpl::vector< bool, int, double > CheckTypes;
template<class X>
class P
{
void init( int x,
typename boost::enable_if< boost::mpl::contains<CheckTypes, X> >::type* dummy = 0);
};
Can Someone help mw on how to solve this issue? An important thing is that the solution should not expect anything from the calling code. And the class is explicitly instantiated.
Thanks,
Gokul.
enable_ifis usually used to discriminate among different definitions of a function. In a certain sense, it is a more powerful way of overloading.It seems you are trying to enable a function only if a condition holds, and give a compilation error otherwise, since you have a single definition of
init. If that’s correct, you may want to look intoBOOST_STATIC_ASSERT(orstatic_assertin c++0x) instead.