variadic templates same number of function arguments as in class

前端 未结 2 1318
面向向阳花
面向向阳花 2021-02-08 03:49

How to define method signature so it will accept same number of arguments as variadic template class definition? For example how to define an Array class:

2条回答
  •  不要未来只要你来
    2021-02-08 04:06

    I assume you want your arguments to be all of the same type, probably using an integer type (I'll just use int). An easy approach is to leverage the parameter pack you already have:

    template 
    struct shape_helper { typedef int type; };
    
    template 
    class Array
    {
    public:
        T& operator()(typename shape_helper::type...);
    }; 
    

提交回复
热议问题