boost - enable_if and constructors -
whats wrong this?
i thought should work when using enable if???
help??
shouldnt second constructor excluded?
#include <iostream> #include <boost/type_traits.hpp> #include <boost/utility/enable_if.hpp> template<class t> class integral_holder{ public: integral_holder(t value_, typename boost::enable_if_c< boost::is_integral<t>::value>::type* ignore = 0) : value(value_){ std::cout << "integral" << std::endl; } integral_holder(t value_, typename boost::enable_if_c< boost::is_floating_point<t>::value>::type* ignore = 0) : value(floor(value_)){ std::cout << "floating point" << std::endl; } private: t value;
};
int main(int argc, const char * argv[]) { integral_holder<int> a(22); return 0; }
when class generated out of class template , in process declarations of constructors instantiated (not theiry body, "signature"), enable_if type invalid , compiler error.
you need make enable_if type depend on template parameter of constructor (make function template). goal works because invalid type formed during deducing function template parameter type when use constructor trigger sfinae case.
Comments
Post a Comment