Simple variadic template function can't instantinate

后端 未结 2 1720
夕颜
夕颜 2020-12-19 15:42

I\'m aware that sizeof...(Args...) yields the number of types in a C++0x packed template argument list, but I wanted to implement it in terms of other features

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-19 16:03

    Konrad's answer should get you going, but I think the more idiomatic way such things are usually expressed is with static member constants, so I just wanted to present that solution:

    #include 
    
    template  struct arg_size;  // no primary definition needed
    
    template  struct arg_size
      : public std::integral_constant::value> { };
    
    template <> struct arg_size<>
      : public std::integral_constant { };
    

    Then you get your argument pack size via arg_size::value.

提交回复
热议问题