Can C++(11) split a converting constructor with implicit and explicitconversion? Plus variadic quer

D

Daryle Walker

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,955
Messages
2,570,117
Members
46,705
Latest member
v_darius

Latest Threads

Top