Template specialization for an empty parameter pack

后端 未结 3 783
走了就别回头了
走了就别回头了 2020-12-30 02:52

I have a variadic template function which calls itself to determine the largest number in a list (constituted by the templatized arguments). I am trying to make a specializa

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-30 03:42

    Personally, I'd prefer using static class members over functions for this sort of thing:

    template  struct max;
    template  struct max {
      static const int value = max::value>::value;
    };    
    template  struct max {
      static const int value = N > M ? N : M;
    };
    
    int main()
    {
      return max<1,2,3>::value;
    }
    

    Update: Using ildjarn's suggestion, here's the less verbose version:

    #include 
    template  struct max;
    template  struct max
      : std::integral_constant::value>::value> { };
    template  struct max
      : std::integral_constant M ? N : M)> { };
    

提交回复
热议问题