Member function template with the number of parameters depending on an integral template parameter

前端 未结 4 546
闹比i
闹比i 2021-02-04 10:27

I have the following class template:

template
class MyClass;

where T is some type, N - num

4条回答
  •  广开言路
    2021-02-04 10:51

    Why not use a static_assert?

    template 
    class MyClass
    {
    public:
        template 
        void foo(Args&&... args)
        {
            static_assert(sizeof...(Args) == N, "Wrong number of arguments.");
            // Rest of the implementation.
        }
    };
    

提交回复
热议问题