Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Can C++(11) split a converting constructor with implicit and explicitconversion? Plus variadic queries. (http://www.velocityreviews.com/forums/t805445-can-c-11-split-a-converting-constructor-with-implicit-and-explicitconversion-plus-variadic-queries.html)

Daryle Walker 11-02-2011 12:11 PM

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57