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

Discussion in 'C++' started by Daryle Walker, Nov 2, 2011.

  1. 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.
    Daryle Walker, Nov 2, 2011
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. The LoxFather

    C plus plus vs C Sharp

    The LoxFather, Aug 9, 2003, in forum: C++
    Replies:
    23
    Views:
    9,208
  2. Colin Walters
    Replies:
    2
    Views:
    523
    Ben Pfaff
    Feb 13, 2004
  3. Ross A. Finlayson
    Replies:
    19
    Views:
    599
    Keith Thompson
    Mar 10, 2005
  4. Replies:
    2
    Views:
    346
    Dave Thompson
    Feb 27, 2006
  5. Replies:
    5
    Views:
    363
Loading...

Share This Page