This is one way to solve your problem on your own:
template<typename T, typename U = NullType> struct TemplateStruct { TemplateStruct(int i) { boost::enable_if< boost::is_same<U,NullType>, void*>::type var = nullptr; std::cout << "One Param == " << i << std::endl; } TemplateStruct(int i, int j) { boost::disable_if< boost::is_same<U,NullType>, void*>::type var = nullptr; std::cout << "Two Param == " << i << "," << j << std::endl; } }; int main() { TemplateStruct<TestType>(1); TemplateStruct<TestType,NonNull>(1,2);
EDIT1: If you assume that your select compiler and the STL implementation that you use support static_assert and type functions (e.g. VS 2010), you can get more efficient error messages if you try to use a disabled ctor:
template<typename T, typename U = NullType> struct TemplateStruct { TemplateStruct(int i) { static_assert( std::is_same<U,NullType>::value, "Cannot use one parameter ctor if U is NullType!" ); std::cout << "One Param == " << i << std::endl; } TemplateStruct(int i, int j) { static_assert( !std::is_same<U,NullType>::value, "Cannot use two parameter ctor if U is not NullType!" ); std::cout << "Two Param == " << i << "," << j << std::endl; } };
EDIT2: Or, if your STL does not have is_same, but you have static_assert:
template<typename T, typename U = NullType> struct TemplateStruct { TemplateStruct(int i) { static_assert( boost::is_same<U,NullType>::value, "Cannot use one parameter ctor if U is NullType!" ); std::cout << "One Param == " << i << std::endl; } TemplateStruct(int i, int j) { static_assert( !boost::is_same<U,NullType>::value, "Cannot use two parameter ctor if U is not NullType!" ); std::cout << "Two Param == " << i << "," << j << std::endl; } };