![]() |
Can C++(11) split a converting constructor with implicit and explicitconversion? Plus variadic queries.
I'm still learning about C++11, and my question concerns having a
cross-version converting constructor template being split into two, and implicit one and an explicit one. template < typename T, unsigned L > class my_type { public: my_type() = default; //... template < typename U, unsigned M > my_type( my_type<U, M> const &other ); template < typename V, unsigned N > explicit my_type( my_type<V, N> const &other ); }; For the first constructor template, I have a mathematical formula connecting M and L that states which values of M should activate this constructor. The second constructor template should match any value of N that doesn't match the formula. Can the std::enable_if template, probably as a defaulted hidden constructor parameter, in either constructor template (or both), help here? I'm also thinking about variadic arguments. That first constructor template is more like: template < unsigned M, typename U0, typename ...U > my_type( my_type<U0, M> const &other0, my_type<U..., M> const &other ); It's a list of elements, where I mandated that the list must have at least one element so it won't be confused with the default constructor. (If I allowed zero arguments, there would be no way to specify M! Constructor templates must imply ALL template parameters.) Do I have the syntax right? How would I actually write the implementation code? I guess I would need some kind of private helper function.... Let's say that the formula is that M must be a divisor of L (and neither can be zero). Is there any way at compiler-time to limit the maximum number of constructor elements? Or do I have to throw an exception when I find out I went over during runtime? (The count will include that one mandatory argument. If M == L, then that mandatory argument must be the sole argument and there should be zero variadic arguments.) Daryle W. |
| All times are GMT. The time now is 02:00 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.