Variable number of constructor parameters depending on integer template

后端 未结 3 991
感动是毒
感动是毒 2021-01-03 02:51

I\'m writing a container storage class template that wraps a private std::array in order to add some functionality to it. The template parametrises the number o

3条回答
  •  孤城傲影
    2021-01-03 03:22

    You could additionally generate a pack of the right size via some template specialization tricks:

    template >
    class Vector;
    
    template 
    class Vector> 
    {
    private:
        std::array vals;
    
        template 
        using double_ = double;
    public:
        Vector(double_... vals)
        {
            ...
        }
    };
    

    That is a non-template constructor which takes N doubles.

提交回复
热议问题